UNPKG

37.2 kBTypeScriptView Raw
1// Type definitions for pino 6.3
2// Project: https://github.com/pinojs/pino.git, http://getpino.io
3// Definitions by: Peter Snider <https://github.com/psnider>
4// BendingBender <https://github.com/BendingBender>
5// Christian Rackerseder <https://github.com/screendriver>
6// GP <https://github.com/paambaati>
7// Alex Ferrando <https://github.com/alferpal>
8// Oleksandr Sidko <https://github.com/mortiy>
9// Harris Lummis <https://github.com/lummish>
10// Raoul Jaeckel <https://github.com/raoulus>
11// Cory Donkin <https://github.com/Cooryd>
12// Adam Vigneaux <https://github.com/AdamVig>
13// Austin Beer <https://github.com/austin-beer>
14// Michel Nemnom <https://github.com/Pegase745>
15// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
16// TypeScript Version: 2.7
17
18/// <reference types="node"/>
19
20import stream = require('stream');
21import http = require('http');
22import { EventEmitter } from 'events';
23import SonicBoom = require('sonic-boom');
24import * as pinoStdSerializers from 'pino-std-serializers';
25
26export = P;
27
28/**
29 * @param [optionsOrStream]: an options object or a writable stream where the logs will be written. It can also receive some log-line metadata, if the
30 * relative protocol is enabled. Default: process.stdout
31 * @returns a new logger instance.
32 */
33declare function P(optionsOrStream?: P.LoggerOptions | P.DestinationStream): P.Logger;
34
35/**
36 * @param [options]: an options object
37 * @param [stream]: a writable stream where the logs will be written. It can also receive some log-line metadata, if the
38 * relative protocol is enabled. Default: process.stdout
39 * @returns a new logger instance.
40 */
41declare function P(options: P.LoggerOptions, stream: P.DestinationStream): P.Logger;
42
43declare namespace P {
44 /**
45 * Holds the current log format version (as output in the v property of each log record).
46 */
47 const LOG_VERSION: number;
48 const levels: LevelMapping;
49 const symbols: {
50 readonly setLevelSym: unique symbol,
51 readonly getLevelSym: unique symbol,
52 readonly levelValSym: unique symbol,
53 readonly useLevelLabelsSym: unique symbol,
54 readonly mixinSym: unique symbol,
55 readonly lsCacheSym: unique symbol,
56 readonly chindingsSym: unique symbol,
57 readonly parsedChindingsSym: unique symbol,
58 readonly asJsonSym: unique symbol,
59 readonly writeSym: unique symbol,
60 readonly serializersSym: unique symbol,
61 readonly redactFmtSym: unique symbol,
62 readonly timeSym: unique symbol,
63 readonly timeSliceIndexSym: unique symbol,
64 readonly streamSym: unique symbol,
65 readonly stringifySym: unique symbol,
66 readonly stringifiersSym: unique symbol,
67 readonly endSym: unique symbol,
68 readonly formatOptsSym: unique symbol,
69 readonly messageKeySym: unique symbol,
70 readonly nestedKeySym: unique symbol,
71 readonly wildcardFirstSym: unique symbol,
72 readonly needsMetadataGsym: unique symbol,
73 readonly useOnlyCustomLevelsSym: unique symbol,
74 readonly formattersSym: unique symbol,
75 readonly hooksSym: unique symbol,
76 };
77 /**
78 * Exposes the Pino package version. Also available on the logger instance.
79 */
80 const version: string;
81
82 type SerializedError = pinoStdSerializers.SerializedError;
83 type SerializedResponse = pinoStdSerializers.SerializedResponse;
84 type SerializedRequest = pinoStdSerializers.SerializedRequest;
85
86 /**
87 * Provides functions for serializing objects common to many projects.
88 */
89 const stdSerializers: {
90 /**
91 * Generates a JSONifiable object from the HTTP `request` object passed to the `createServer` callback of Node's HTTP server.
92 */
93 req: typeof pinoStdSerializers.req;
94 /**
95 * Generates a JSONifiable object from the HTTP `response` object passed to the `createServer` callback of Node's HTTP server.
96 */
97 res: typeof pinoStdSerializers.res;
98 /**
99 * Serializes an Error object.
100 */
101 err: typeof pinoStdSerializers.err;
102 /**
103 * Returns an object:
104 * ```
105 * {
106 * req: {}
107 * }
108 * ```
109 * where req is the request as serialized by the standard request serializer.
110 * @param req The request to serialize
111 * @return An object
112 */
113 mapHttpRequest: typeof pinoStdSerializers.mapHttpRequest;
114 /**
115 * Returns an object:
116 * ```
117 * {
118 * res: {}
119 * }
120 * ```
121 * where res is the response as serialized by the standard response serializer.
122 * @param res The response to serialize.
123 * @return An object.
124 */
125 mapHttpResponse: typeof pinoStdSerializers.mapHttpResponse;
126 /**
127 * A utility method for wrapping the default error serializer. Allows custom serializers to work with the
128 * already serialized object.
129 * @param customSerializer The custom error serializer. Accepts a single parameter: the newly serialized
130 * error object. Returns the new (or updated) error object.
131 * @return A new error serializer.
132 */
133 wrapErrorSerializer: typeof pinoStdSerializers.wrapErrorSerializer;
134 /**
135 * A utility method for wrapping the default request serializer. Allows custom serializers to work with the
136 * already serialized object.
137 * @param customSerializer The custom request serializer. Accepts a single parameter: the newly serialized
138 * request object. Returns the new (or updated) request object.
139 * @return A new error serializer.
140 */
141 wrapRequestSerializer: typeof pinoStdSerializers.wrapRequestSerializer;
142 /**
143 * A utility method for wrapping the default response serializer. Allows custom serializers to work with the
144 * already serialized object.
145 * @param customSerializer The custom response serializer. Accepts a single parameter: the newly serialized
146 * response object. Returns the new (or updated) response object.
147 * @return A new error serializer.
148 */
149 wrapResponseSerializer: typeof pinoStdSerializers.wrapResponseSerializer;
150 };
151 /**
152 * Provides functions for generating the timestamp property in the log output. You can set the `timestamp` option during
153 * initialization to one of these functions to adjust the output format. Alternatively, you can specify your own time function.
154 * A time function must synchronously return a string that would be a valid component of a JSON string. For example,
155 * the default function returns a string like `,"time":1493426328206`.
156 */
157 const stdTimeFunctions: {
158 /**
159 * The default time function for Pino. Returns a string like `,"time":1493426328206`.
160 */
161 epochTime: TimeFn;
162 /*
163 * Returns the seconds since Unix epoch
164 */
165 unixTime: TimeFn;
166 /**
167 * Returns an empty string. This function is used when the `timestamp` option is set to `false`.
168 */
169 nullTime: TimeFn;
170 /*
171 * Returns ISO 8601-formatted time in UTC
172 */
173 isoTime: TimeFn;
174 };
175
176 /**
177 * Equivalent of SonicBoom constructor options object
178 */
179 // TODO: use SonicBoom constructor options interface when available
180 interface DestinationObjectOptions {
181 fd?: string | number;
182 dest?: string;
183 minLength?: number;
184 sync?: boolean;
185 }
186
187 /**
188 * Create a Pino Destination instance: a stream-like object with significantly more throughput (over 30%) than a standard Node.js stream.
189 * @param [dest]: The `destination` parameter, at a minimum must be an object with a `write` method. An ordinary Node.js
190 * `stream` can be passed as the destination (such as the result of `fs.createWriteStream`) but for peak log
191 * writing performance it is strongly recommended to use `pino.destination` to create the destination stream.
192 * @returns A Sonic-Boom stream to be used as destination for the pino function
193 */
194 function destination(dest?: string | number | DestinationObjectOptions | DestinationStream | NodeJS.WritableStream): SonicBoom;
195
196 /**
197 * Create an extreme mode destination. This yields an additional 60% performance boost.
198 * There are trade-offs that should be understood before usage.
199 * @param [fileDescriptor]: File path or numerical file descriptor, by default 1
200 * @returns A Sonic-Boom stream to be used as destination for the pino function
201 */
202 function extreme(fileDescriptor?: string | number): SonicBoom;
203
204 /**
205 * The pino.final method can be used to create an exit listener function.
206 * This listener function can be supplied to process exit events.
207 * The exit listener function will call the handler with
208 * @param [logger]: pino logger that serves as reference for the final logger
209 * @param [handler]: Function that will be called by the handler returned from this function
210 * @returns Exit listener function that can be supplied to process exit events and will call the supplied handler function
211 */
212 function final(
213 logger: Logger,
214 handler: (error: Error, finalLogger: Logger, ...args: any[]) => void,
215 ): (error: Error | null, ...args: any[]) => void;
216
217 /**
218 * The pino.final method can be used to acquire a final logger instance that synchronously flushes on every write.
219 * @param [logger]: pino logger that serves as reference for the final logger
220 * @returns Final, synchronous logger
221 */
222 function final(logger: Logger): Logger;
223
224 interface LevelMapping {
225 /**
226 * Returns the mappings of level names to their respective internal number representation.
227 */
228 values: { [level: string]: number };
229 /**
230 * Returns the mappings of level internal level numbers to their string representations.
231 */
232 labels: { [level: number]: string };
233 }
234 type TimeFn = () => string;
235 type MixinFn = () => object;
236
237 interface DestinationStream {
238 write(msg: string): void;
239 }
240
241 interface LoggerOptions {
242 /**
243 * Avoid error causes by circular references in the object tree. Default: `true`.
244 */
245 safe?: boolean;
246 /**
247 * The name of the logger. Default: `undefined`.
248 */
249 name?: string;
250 /**
251 * an object containing functions for custom serialization of objects.
252 * These functions should return an JSONifiable object and they should never throw. When logging an object,
253 * each top-level property matching the exact key of a serializer will be serialized using the defined serializer.
254 */
255 serializers?: { [key: string]: SerializerFn };
256 /**
257 * Enables or disables the inclusion of a timestamp in the log message. If a function is supplied, it must
258 * synchronously return a JSON string representation of the time. If set to `false`, no timestamp will be included in the output.
259 * See stdTimeFunctions for a set of available functions for passing in as a value for this option.
260 * Caution: any sort of formatted time will significantly slow down Pino's performance.
261 */
262 timestamp?: TimeFn | boolean;
263 /**
264 * One of the supported levels or `silent` to disable logging. Any other value defines a custom level and
265 * requires supplying a level value via `levelVal`. Default: 'info'.
266 */
267 level?: LevelWithSilent | string;
268 /**
269 * Outputs the level as a string instead of integer. Default: `false`.
270 */
271 useLevelLabels?: boolean;
272 /**
273 * Changes the property `level` to any string value you pass in. Default: 'level'
274 */
275 levelKey?: string;
276 /**
277 * (DEPRECATED, use `levelKey`) Changes the property `level` to any string value you pass in. Default: 'level'
278 */
279 changeLevelName?: string;
280 /**
281 * Use this option to define additional logging levels.
282 * The keys of the object correspond the namespace of the log level, and the values should be the numerical value of the level.
283 */
284 customLevels?: { [key: string]: number };
285 /**
286 * Use this option to only use defined `customLevels` and omit Pino's levels.
287 * Logger's default `level` must be changed to a value in `customLevels` in order to use `useOnlyCustomLevels`
288 * Warning: this option may not be supported by downstream transports.
289 */
290 useOnlyCustomLevels?: boolean;
291
292 /**
293 * If provided, the `mixin` function is called each time one of the active logging methods
294 * is called. The function must synchronously return an object. The properties of the
295 * returned object will be added to the logged JSON.
296 */
297 mixin?: MixinFn;
298
299 /**
300 * As an array, the redact option specifies paths that should have their values redacted from any log output.
301 *
302 * Each path must be a string using a syntax which corresponds to JavaScript dot and bracket notation.
303 *
304 * If an object is supplied, three options can be specified:
305 *
306 * paths (String[]): Required. An array of paths
307 * censor (String): Optional. A value to overwrite key which are to be redacted. Default: '[Redacted]'
308 * remove (Boolean): Optional. Instead of censoring the value, remove both the key and the value. Default: false
309 */
310 redact?: string[] | redactOptions;
311
312 /**
313 * When defining a custom log level via level, set to an integer value to define the new level. Default: `undefined`.
314 */
315 levelVal?: number;
316 /**
317 * The string key for the 'message' in the JSON object. Default: "msg".
318 */
319 messageKey?: string;
320 /**
321 * The string key to place any logged object under.
322 */
323 nestedKey?: string;
324 /**
325 * Enables pino.pretty. This is intended for non-production configurations. This may be set to a configuration
326 * object as outlined in http://getpino.io/#/docs/API?id=pretty. Default: `false`.
327 */
328 prettyPrint?: boolean | PrettyOptions;
329 /**
330 * Allows to optionally define which prettifier module to use.
331 */
332 // TODO: use type definitions from 'pino-pretty' when available.
333 prettifier?: any;
334 /**
335 * This function will be invoked during process shutdown when `extreme` is set to `true`. If you do not specify
336 * a function, Pino will invoke `process.exit(0)` when no error has occurred, and `process.exit(1)` otherwise.
337 * If you do specify a function, it is up to you to terminate the process; you must perform only synchronous
338 * operations at this point. See http://getpino.io/#/docs/extreme for more detail.
339 */
340 onTerminated?(eventName: string, err: any): void;
341 /**
342 * Enables logging. Default: `true`.
343 */
344 enabled?: boolean;
345 /**
346 * Browser only, see http://getpino.io/#/docs/browser.
347 */
348 browser?: {
349 /**
350 * The `asObject` option will create a pino-like log object instead of passing all arguments to a console
351 * method. When `write` is set, `asObject` will always be true.
352 *
353 * @example
354 * pino.info('hi') // creates and logs {msg: 'hi', level: 30, time: <ts>}
355 */
356 asObject?: boolean;
357 /**
358 * Instead of passing log messages to `console.log` they can be passed to a supplied function. If `write` is
359 * set to a single function, all logging objects are passed to this function. If `write` is an object, it
360 * can have methods that correspond to the levels. When a message is logged at a given level, the
361 * corresponding method is called. If a method isn't present, the logging falls back to using the `console`.
362 *
363 * @example
364 * const pino = require('pino')({
365 * browser: {
366 * write: (o) => {
367 * // do something with o
368 * }
369 * }
370 * })
371 *
372 * @example
373 * const pino = require('pino')({
374 * browser: {
375 * write: {
376 * info: function (o) {
377 * //process info log object
378 * },
379 * error: function (o) {
380 * //process error log object
381 * }
382 * }
383 * }
384 * })
385 */
386 write?:
387 | WriteFn
388 | ({
389 fatal?: WriteFn;
390 error?: WriteFn;
391 warn?: WriteFn;
392 info?: WriteFn;
393 debug?: WriteFn;
394 trace?: WriteFn;
395 } & { [logLevel: string]: WriteFn });
396
397 /**
398 * The serializers provided to `pino` are ignored by default in the browser, including the standard
399 * serializers provided with Pino. Since the default destination for log messages is the console, values
400 * such as `Error` objects are enhanced for inspection, which they otherwise wouldn't be if the Error
401 * serializer was enabled. We can turn all serializers on or we can selectively enable them via an array.
402 *
403 * When `serialize` is `true` the standard error serializer is also enabled (see
404 * {@link https://github.com/pinojs/pino/blob/master/docs/api.md#pino-stdserializers}). This is a global
405 * serializer which will apply to any `Error` objects passed to the logger methods.
406 *
407 * If `serialize` is an array the standard error serializer is also automatically enabled, it can be
408 * explicitly disabled by including a string in the serialize array: `!stdSerializers.err` (see example).
409 *
410 * The `serialize` array also applies to any child logger serializers (see
411 * {@link https://github.com/pinojs/pino/blob/master/docs/api.md#bindingsserializers-object} for how to
412 * set child-bound serializers).
413 *
414 * Unlike server pino the serializers apply to every object passed to the logger method, if the `asObject`
415 * option is `true`, this results in the serializers applying to the first object (as in server pino).
416 *
417 * For more info on serializers see
418 * {@link https://github.com/pinojs/pino/blob/master/docs/api.md#serializers-object}.
419 *
420 * @example
421 * const pino = require('pino')({
422 * browser: {
423 * serialize: true
424 * }
425 * })
426 *
427 * @example
428 * const pino = require('pino')({
429 * serializers: {
430 * custom: myCustomSerializer,
431 * another: anotherSerializer
432 * },
433 * browser: {
434 * serialize: ['custom']
435 * }
436 * })
437 * // following will apply myCustomSerializer to the custom property,
438 * // but will not apply anotherSerializer to another key
439 * pino.info({custom: 'a', another: 'b'})
440 *
441 * @example
442 * const pino = require('pino')({
443 * serializers: {
444 * custom: myCustomSerializer,
445 * another: anotherSerializer
446 * },
447 * browser: {
448 * serialize: ['!stdSerializers.err', 'custom'] //will not serialize Errors, will serialize `custom` keys
449 * }
450 * })
451 */
452 serialize?: boolean | string[];
453
454 /**
455 * Options for transmission of logs.
456 *
457 * @example
458 * const pino = require('pino')({
459 * browser: {
460 * transmit: {
461 * level: 'warn',
462 * send: function (level, logEvent) {
463 * if (level === 'warn') {
464 * // maybe send the logEvent to a separate endpoint
465 * // or maybe analyse the messages further before sending
466 * }
467 * // we could also use the `logEvent.level.value` property to determine
468 * // numerical value
469 * if (logEvent.level.value >= 50) { // covers error and fatal
470 *
471 * // send the logEvent somewhere
472 * }
473 * }
474 * }
475 * }
476 * })
477 */
478 transmit?: {
479 /**
480 * Specifies the minimum level (inclusive) of when the `send` function should be called, if not supplied
481 * the `send` function will be called based on the main logging `level` (set via `options.level`,
482 * defaulting to `info`).
483 */
484 level?: Level | string;
485 /**
486 * Remotely record log messages.
487 *
488 * @description Called after writing the log message.
489 */
490 send: (level: Level, logEvent: LogEvent) => void;
491 };
492 };
493 /**
494 * key-value object added as child logger to each log line. If set to null the base child logger is not added
495 */
496 base?: { [key: string]: any } | null;
497
498 /**
499 * An object containing functions for formatting the shape of the log lines.
500 * These functions should return a JSONifiable object and should never throw.
501 * These functions allow for full customization of the resulting log lines.
502 * For example, they can be used to change the level key name or to enrich the default metadata.
503 */
504 formatters?: {
505 /**
506 * Changes the shape of the log level.
507 * The default shape is { level: number }.
508 * The function takes two arguments, the label of the level (e.g. 'info') and the numeric value (e.g. 30).
509 */
510 level?: (level: string, number: number) => object;
511 /**
512 * Changes the shape of the bindings.
513 * The default shape is { pid, hostname }.
514 * The function takes a single argument, the bindings object.
515 * It will be called every time a child logger is created.
516 */
517 bindings?: (bindings: Bindings) => object;
518 /**
519 * Changes the shape of the log object.
520 * This function will be called every time one of the log methods (such as .info) is called.
521 * All arguments passed to the log method, except the message, will be pass to this function.
522 * By default it does not change the shape of the log object.
523 */
524 log?: (object: object) => object;
525 };
526
527 /**
528 * An object mapping to hook functions. Hook functions allow for customizing internal logger operations.
529 * Hook functions must be synchronous functions.
530 */
531 hooks?: {
532 /**
533 * Allows for manipulating the parameters passed to logger methods. The signature for this hook is
534 * logMethod (args, method, level) {}, where args is an array of the arguments that were passed to the
535 * log method and method is the log method itself, and level is the log level. This hook must invoke the method function by
536 * using apply, like so: method.apply(this, newArgumentsArray).
537 */
538 logMethod?: (args: any[], method: LogFn, level: number) => void;
539 };
540 }
541
542 type MessageFormatFunc = (log: LogDescriptor, messageKey: string, levelLabel: string) => string;
543
544 interface PrettyOptions {
545 /**
546 * Translate the epoch time value into a human readable date and time string.
547 * This flag also can set the format string to apply when translating the date to human readable format.
548 * The default format is yyyy-mm-dd HH:MM:ss.l o in UTC.
549 * For a list of available pattern letters see the {@link https://www.npmjs.com/package/dateformat|dateformat documentation}.
550 */
551 translateTime?: boolean | string;
552 /**
553 * If set to true, it will print the name of the log level as the first field in the log line. Default: `false`.
554 */
555 levelFirst?: boolean;
556 /**
557 * The key in the JSON object to use as the highlighted message. Default: "msg".
558 */
559 messageKey?: string;
560 /**
561 * The key in the JSON object to use for timestamp display. Default: "time".
562 */
563 timestampKey?: string;
564 /**
565 * Format output of message, e.g. {level} - {pid} will output message: INFO - 1123 Default: `false`.
566 *
567 * @example
568 * ```typescript
569 * {
570 * messageFormat: (log, messageKey) => {
571 * const message = log[messageKey];
572 * if (log.requestId) return `[${log.requestId}] ${message}`;
573 * return message;
574 * }
575 * }
576 * ```
577 */
578 messageFormat?: false | string | MessageFormatFunc;
579 /**
580 * If set to true, will add color information to the formatted output message. Default: `false`.
581 */
582 colorize?: boolean;
583 /**
584 * Appends carriage return and line feed, instead of just a line feed, to the formatted log line.
585 */
586 crlf?: boolean;
587 /**
588 * Define the log keys that are associated with error like objects. Default: ["err", "error"]
589 */
590 errorLikeObjectKeys?: string[];
591 /**
592 * When formatting an error object, display this list of properties.
593 * The list should be a comma separated list of properties. Default: ''
594 */
595 errorProps?: string;
596 /**
597 * Specify a search pattern according to {@link http://jmespath.org|jmespath}
598 */
599 search?: string;
600 /**
601 * Ignore one or several keys. Example: "time,hostname"
602 */
603 ignore?: string;
604 /**
605 * Suppress warning on first synchronous flushing.
606 */
607 suppressFlushSyncWarning?: boolean;
608 }
609
610 type Level = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
611 type LevelWithSilent = Level | 'silent';
612
613 type SerializerFn = (value: any) => any;
614 type WriteFn = (o: object) => void;
615
616 /**
617 * Describes a log line.
618 */
619 type LogDescriptor = Record<string, any>; // TODO replace `any` with `unknown` when TypeScript version >= 3.0
620
621 interface Bindings {
622 level?: Level | string;
623 serializers?: { [key: string]: SerializerFn };
624 [key: string]: any;
625 }
626
627 /**
628 * A data structure representing a log message, it represents the arguments passed to a logger statement, the level
629 * at which they were logged and the hierarchy of child bindings.
630 *
631 * @description By default serializers are not applied to log output in the browser, but they will always be applied
632 * to `messages` and `bindings` in the `logEvent` object. This allows us to ensure a consistent format for all
633 * values between server and client.
634 */
635 interface LogEvent {
636 /**
637 * Unix epoch timestamp in milliseconds, the time is taken from the moment the logger method is called.
638 */
639 ts: number;
640 /**
641 * All arguments passed to logger method, (for instance `logger.info('a', 'b', 'c')` would result in `messages`
642 * array `['a', 'b', 'c']`).
643 */
644 messages: any[];
645 /**
646 * Represents each child logger (if any), and the relevant bindings.
647 *
648 * @description For instance, given `logger.child({a: 1}).child({b: 2}).info({c: 3})`, the bindings array would
649 * hold `[{a: 1}, {b: 2}]` and the `messages` array would be `[{c: 3}]`. The `bindings` are ordered according to
650 * their position in the child logger hierarchy, with the lowest index being the top of the hierarchy.
651 */
652 bindings: Bindings[];
653 /**
654 * Holds the `label` (for instance `info`), and the corresponding numerical `value` (for instance `30`).
655 * This could be important in cases where client side level values and labels differ from server side.
656 */
657 level: {
658 label: string;
659 value: number;
660 };
661 }
662
663 type Logger = BaseLogger & { [key: string]: LogFn };
664
665 interface BaseLogger extends EventEmitter {
666 /**
667 * Exposes the current version of Pino.
668 */
669 readonly pino: string;
670 /**
671 * Holds the current log format version (as output in the v property of each log record).
672 */
673 readonly LOG_VERSION: number;
674 /**
675 * Exposes the Pino package version. Also available on the exported pino function.
676 */
677 readonly version: string;
678
679 levels: LevelMapping;
680
681 /**
682 * Set this property to the desired logging level. In order of priority, available levels are:
683 *
684 * - 'fatal'
685 * - 'error'
686 * - 'warn'
687 * - 'info'
688 * - 'debug'
689 * - 'trace'
690 *
691 * The logging level is a __minimum__ level. For instance if `logger.level` is `'info'` then all `'fatal'`, `'error'`, `'warn'`,
692 * and `'info'` logs will be enabled.
693 *
694 * You can pass `'silent'` to disable logging.
695 */
696 level: LevelWithSilent | string;
697 /**
698 * Outputs the level as a string instead of integer.
699 */
700 useLevelLabels: boolean;
701 /**
702 * Define additional logging levels.
703 */
704 customLevels: { [key: string]: number };
705 /**
706 * Use only defined `customLevels` and omit Pino's levels.
707 */
708 useOnlyCustomLevels: boolean;
709 /**
710 * Returns the integer value for the logger instance's logging level.
711 */
712 levelVal: number;
713
714 /**
715 * Registers a listener function that is triggered when the level is changed.
716 * Note: When browserified, this functionality will only be available if the `events` module has been required elsewhere
717 * (e.g. if you're using streams in the browser). This allows for a trade-off between bundle size and functionality.
718 *
719 * @param event: only ever fires the `'level-change'` event
720 * @param listener: The listener is passed four arguments: `levelLabel`, `levelValue`, `previousLevelLabel`, `previousLevelValue`.
721 */
722 on(event: 'level-change', listener: LevelChangeEventListener): this;
723 addListener(event: 'level-change', listener: LevelChangeEventListener): this;
724 once(event: 'level-change', listener: LevelChangeEventListener): this;
725 prependListener(event: 'level-change', listener: LevelChangeEventListener): this;
726 prependOnceListener(event: 'level-change', listener: LevelChangeEventListener): this;
727 removeListener(event: 'level-change', listener: LevelChangeEventListener): this;
728
729 /**
730 * Creates a child logger, setting all key-value pairs in `bindings` as properties in the log lines. All serializers will be applied to the given pair.
731 * Child loggers use the same output stream as the parent and inherit the current log level of the parent at the time they are spawned.
732 * From v2.x.x the log level of a child is mutable (whereas in v1.x.x it was immutable), and can be set independently of the parent.
733 * If a `level` property is present in the object passed to `child` it will override the child logger level.
734 *
735 * @param bindings: an object of key-value pairs to include in log lines as properties.
736 * @returns a child logger instance.
737 */
738 child(bindings: Bindings): Logger;
739
740 /**
741 * Log at `'fatal'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
742 * If more args follows `msg`, these will be used to format `msg` using `util.format`.
743 *
744 * @typeParam T: the interface of the object being serialized. Default is object.
745 * @param obj: object to be serialized
746 * @param msg: the log message to write
747 * @param ...args: format string values when `msg` is a format string
748 */
749 fatal: LogFn;
750 /**
751 * Log at `'error'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
752 * If more args follows `msg`, these will be used to format `msg` using `util.format`.
753 *
754 * @typeParam T: the interface of the object being serialized. Default is object.
755 * @param obj: object to be serialized
756 * @param msg: the log message to write
757 * @param ...args: format string values when `msg` is a format string
758 */
759 error: LogFn;
760 /**
761 * Log at `'warn'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
762 * If more args follows `msg`, these will be used to format `msg` using `util.format`.
763 *
764 * @typeParam T: the interface of the object being serialized. Default is object.
765 * @param obj: object to be serialized
766 * @param msg: the log message to write
767 * @param ...args: format string values when `msg` is a format string
768 */
769 warn: LogFn;
770 /**
771 * Log at `'info'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
772 * If more args follows `msg`, these will be used to format `msg` using `util.format`.
773 *
774 * @typeParam T: the interface of the object being serialized. Default is object.
775 * @param obj: object to be serialized
776 * @param msg: the log message to write
777 * @param ...args: format string values when `msg` is a format string
778 */
779 info: LogFn;
780 /**
781 * Log at `'debug'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
782 * If more args follows `msg`, these will be used to format `msg` using `util.format`.
783 *
784 * @typeParam T: the interface of the object being serialized. Default is object.
785 * @param obj: object to be serialized
786 * @param msg: the log message to write
787 * @param ...args: format string values when `msg` is a format string
788 */
789 debug: LogFn;
790 /**
791 * Log at `'trace'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
792 * If more args follows `msg`, these will be used to format `msg` using `util.format`.
793 *
794 * @typeParam T: the interface of the object being serialized. Default is object.
795 * @param obj: object to be serialized
796 * @param msg: the log message to write
797 * @param ...args: format string values when `msg` is a format string
798 */
799 trace: LogFn;
800 /**
801 * Noop function.
802 */
803 silent: LogFn;
804
805 /**
806 * Flushes the content of the buffer in extreme mode. It has no effect if extreme mode is not enabled.
807 */
808 flush(): void;
809
810 /**
811 * A utility method for determining if a given log level will write to the destination.
812 */
813 isLevelEnabled(level: LevelWithSilent | string): boolean;
814
815 /**
816 * Returns an object containing all the current bindings, cloned from the ones passed in via logger.child().
817 */
818 bindings(): Bindings;
819 }
820
821 type LevelChangeEventListener = (
822 lvl: LevelWithSilent | string,
823 val: number,
824 prevLvl: LevelWithSilent | string,
825 prevVal: number,
826 ) => void;
827
828 interface LogFn {
829 /* tslint:disable:no-unnecessary-generics */
830 <T extends object>(obj: T, msg?: string, ...args: any[]): void;
831 (msg: string, ...args: any[]): void;
832 }
833
834 interface redactOptions {
835 paths: string[];
836 censor?: string | ((v: any) => any);
837 remove?: boolean;
838 }
839}
840
\No newline at end of file