Merge pull request #30131 from alferpal/master

Update pino definitions for 5.8
This commit is contained in:
Daniel Rosenwasser
2018-10-30 20:40:57 -07:00
committed by GitHub
6 changed files with 103 additions and 35 deletions
+17 -26
View File
@@ -1,9 +1,10 @@
// Type definitions for pino 5.6
// Type definitions for pino 5.8
// Project: https://github.com/pinojs/pino.git
// Definitions by: Peter Snider <https://github.com/psnider>
// BendingBender <https://github.com/BendingBender>
// Christian Rackerseder <https://github.com/screendriver>
// GP <https://github.com/paambaati>
// Alex Ferrando <https://github.com/alferpal>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -12,6 +13,7 @@
import * as stream from 'stream';
import * as http from 'http';
import { EventEmitter } from 'events';
import SonicBoom = require('sonic-boom');
export = P;
@@ -20,7 +22,7 @@ export = P;
* relative protocol is enabled. Default: process.stdout
* @returns a new logger instance.
*/
declare function P(optionsOrStream?: P.LoggerOptions | stream.Writable | stream.Duplex | stream.Transform | NodeJS.WritableStream): P.Logger;
declare function P(optionsOrStream?: P.LoggerOptions | stream.Writable | stream.Duplex | stream.Transform | NodeJS.WritableStream | SonicBoom): P.Logger;
/**
* @param [options]: an options object
@@ -28,7 +30,7 @@ declare function P(optionsOrStream?: P.LoggerOptions | stream.Writable | stream.
* relative protocol is enabled. Default: process.stdout
* @returns a new logger instance.
*/
declare function P(options: P.LoggerOptions, stream: stream.Writable | stream.Duplex | stream.Transform | NodeJS.WritableStream): P.Logger;
declare function P(options: P.LoggerOptions, stream: stream.Writable | stream.Duplex | stream.Transform | NodeJS.WritableStream | SonicBoom): P.Logger;
declare namespace P {
/**
@@ -75,11 +77,6 @@ declare namespace P {
* The default time function for Pino. Returns a string like `,"time":1493426328206`.
*/
epochTime: TimeFn;
/**
* Returns an ISO formatted string like `,"time":"2017-04-29T004749.354Z"`. It is highly recommended that you avoid this function.
* It incurs a significant performance penalty.
*/
slowTime: TimeFn;
/**
* Returns an empty string. This function is used when the `timestamp` option is set to `false`.
*/
@@ -87,12 +84,19 @@ declare namespace P {
};
/**
* Provides access to the CLI log prettifier as an API.
* This can also be enabled via the constructor by setting the `prettyPrint` option to either `true` or a configuration object described in this section.
* @param [options]: an options object
* @returns A transform stream to be used as input for the constructor.
* Create a Pino Destination instance: a stream-like object with significantly more throughput (over 30%) than a standard Node.js stream.
* @param [fileDescriptor]: File path or numerical file descriptor, by default 1
* @returns A Sonic-Boom stream to be used as destination for the pino function
*/
function pretty(options?: PrettyOptions): stream.Transform;
function destination(fileDescriptor?: string | number): SonicBoom;
/**
* Create an extreme mode destination. This yields an additional 60% performance boost.
* There are trade-offs that should be understood before usage.
* @param [fileDescriptor]: File path or numerical file descriptor, by default 1
* @returns A Sonic-Boom stream to be used as destination for the pino function
*/
function extreme(fileDescriptor?: string | number): SonicBoom;
interface LevelMapping {
/**
@@ -128,19 +132,6 @@ declare namespace P {
* Caution: any sort of formatted time will significantly slow down Pino's performance.
*/
timestamp?: TimeFn | false;
/**
* @deprecated
* This option is scheduled to be removed in Pino 5.0.0. Use `timestamp: pino.stdTimeFunctions.slowTime` instead.
* Outputs ISO time stamps ('2016-03-09T15:18:53.889Z') instead of Epoch time stamps (1457536759176).
* WARNING: This option carries a 25% performance drop, we recommend using default Epoch timestamps and transforming logs after if required.
* The pino -t command will do this for you (see CLI). Default: `false`.
*/
slowtime?: boolean;
/**
* Enables extreme mode, yields an additional 60% performance (from 250ms down to 100ms per 10000 ops).
* There are trade-off's should be understood before usage. See Extreme mode explained. Default: `false`.
*/
extreme?: boolean;
/**
* One of the supported levels or `silent` to disable logging. Any other value defines a custom level and
* requires supplying a level value via `levelVal`. Default: 'info'.
-9
View File
@@ -22,15 +22,6 @@ const log2: pino.Logger = pino({
}
});
const pretty = pino.pretty();
pretty.pipe(process.stdout);
const log3 = pino({
name: 'app',
safe: true
}, pretty);
log3.child({widget: 'foo'}).info('hello');
log3.child({widget: 'bar'}).warn('hello 2');
pino({
browser: {
write(o) {
+50
View File
@@ -0,0 +1,50 @@
// Type definitions for sonic-boom 0.6
// Project: https://github.com/mcollina/sonic-boom.git
// Definitions by: Alex Ferrando <https://github.com/alferpal>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node"/>
import { EventEmitter } from 'events';
export = SonicBoom;
declare class SonicBoom extends EventEmitter {
/**
* @param [fileDescriptor] File path or numerical file descriptor
* relative protocol is enabled. Default: process.stdout
* @returns a new sonic-boom instance
*/
constructor(fileDescriptor: string | number)
/**
* Writes the string to the file. It will return false to signal the producer to slow down.
*/
write(string: string): void;
/**
* Writes the current buffer to the file if a write was not in progress.
* Do nothing if minLength is zero or if it is already writing.
*/
flush(): void;
/**
* Reopen the file in place, useful for log rotation.
*/
reopen(file: string): void;
/**
* Flushes the buffered data synchronously. This is a costly operation.
*/
flushSync(): void;
/**
* Closes the stream, the data will be flushed down asynchronously
*/
end(): void;
/**
* Closes the stream immediately, the data is not flushed.
*/
destroy(): void;
}
+12
View File
@@ -0,0 +1,12 @@
import SonicBoom = require('sonic-boom');
const sonic = new SonicBoom(1);
sonic.write('hello sonic\n');
sonic.flush();
sonic.flushSync();
sonic.end();
sonic.destroy();
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"sonic-boom-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }