Skip to content

Commit

Permalink
Merge 6a9d48e into 3ec9946
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad committed Aug 26, 2021
2 parents 3ec9946 + 6a9d48e commit 4e6fb85
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 61 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -71,7 +71,7 @@
"bunyan": "^1.8.14",
"docsify-cli": "^4.4.1",
"eslint": "^7.17.0",
"eslint-config-standard": "^16.0.2",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
Expand Down
110 changes: 52 additions & 58 deletions pino.d.ts
Expand Up @@ -50,7 +50,6 @@ declare namespace P {
/**
* Holds the current log format version (as output in the v property of each log record).
*/
const LOG_VERSION: number;
const levels: LevelMapping;
const symbols: {
readonly setLevelSym: unique symbol;
Expand Down Expand Up @@ -728,23 +727,20 @@ declare namespace P {
};
}

type Logger = BaseLogger & { [key: string]: LogFn };
type Logger = BaseLogger & LoggerExtras & Record<string, any>;

interface BaseLogger extends EventEmitter {
interface BaseLogger {
/**
* Exposes the current version of Pino.
*/
readonly pino: string;
/**
* Holds the current log format version (as output in the v property of each log record).
*/
readonly LOG_VERSION: number;
/**
* Exposes the Pino package version. Also available on the exported pino function.
* 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.
* 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.
* 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.
* If a `level` property is present in the object passed to `child` it will override the child logger level.
*
* @param bindings: an object of key-value pairs to include in log lines as properties.
* @param options: an options object that will override child logger inherited options.
* @returns a child logger instance.
*/
readonly version: string;

levels: LevelMapping;
child(bindings: Bindings, options?: ChildLoggerOptions): BaseLogger;

/**
* Set this property to the desired logging level. In order of priority, available levels are:
Expand All @@ -762,49 +758,6 @@ declare namespace P {
* You can pass `'silent'` to disable logging.
*/
level: LevelWithSilent | string;
/**
* Outputs the level as a string instead of integer.
*/
useLevelLabels: boolean;
/**
* Define additional logging levels.
*/
customLevels: { [key: string]: number };
/**
* Use only defined `customLevels` and omit Pino's levels.
*/
useOnlyCustomLevels: boolean;
/**
* Returns the integer value for the logger instance's logging level.
*/
levelVal: number;

/**
* Registers a listener function that is triggered when the level is changed.
* Note: When browserified, this functionality will only be available if the `events` module has been required elsewhere
* (e.g. if you're using streams in the browser). This allows for a trade-off between bundle size and functionality.
*
* @param event: only ever fires the `'level-change'` event
* @param listener: The listener is passed four arguments: `levelLabel`, `levelValue`, `previousLevelLabel`, `previousLevelValue`.
*/
on(event: "level-change", listener: LevelChangeEventListener): this;
addListener(event: "level-change", listener: LevelChangeEventListener): this;
once(event: "level-change", listener: LevelChangeEventListener): this;
prependListener(event: "level-change", listener: LevelChangeEventListener): this;
prependOnceListener(event: "level-change", listener: LevelChangeEventListener): this;
removeListener(event: "level-change", listener: LevelChangeEventListener): this;

/**
* 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.
* 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.
* 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.
* If a `level` property is present in the object passed to `child` it will override the child logger level.
*
* @param bindings: an object of key-value pairs to include in log lines as properties.
* @param options: an options object that will override child logger inherited options.
* @returns a child logger instance.
*/
child(bindings: Bindings, options?: ChildLoggerOptions): Logger;

/**
* Log at `'fatal'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
Expand Down Expand Up @@ -870,6 +823,47 @@ declare namespace P {
* Noop function.
*/
silent: LogFn;
}

interface LoggerExtras extends EventEmitter {
/**
* Exposes the Pino package version. Also available on the exported pino function.
*/
readonly version: string;

levels: LevelMapping;

/**
* Outputs the level as a string instead of integer.
*/
useLevelLabels: boolean;
/**
* Define additional logging levels.
*/
customLevels: { [key: string]: number };
/**
* Use only defined `customLevels` and omit Pino's levels.
*/
useOnlyCustomLevels: boolean;
/**
* Returns the integer value for the logger instance's logging level.
*/
levelVal: number;

/**
* Registers a listener function that is triggered when the level is changed.
* Note: When browserified, this functionality will only be available if the `events` module has been required elsewhere
* (e.g. if you're using streams in the browser). This allows for a trade-off between bundle size and functionality.
*
* @param event: only ever fires the `'level-change'` event
* @param listener: The listener is passed four arguments: `levelLabel`, `levelValue`, `previousLevelLabel`, `previousLevelValue`.
*/
on(event: "level-change", listener: LevelChangeEventListener): this;
addListener(event: "level-change", listener: LevelChangeEventListener): this;
once(event: "level-change", listener: LevelChangeEventListener): this;
prependListener(event: "level-change", listener: LevelChangeEventListener): this;
prependOnceListener(event: "level-change", listener: LevelChangeEventListener): this;
removeListener(event: "level-change", listener: LevelChangeEventListener): this;

/**
* A utility method for determining if a given log level will write to the destination.
Expand Down
9 changes: 7 additions & 2 deletions test/types/pino.test-d.ts
@@ -1,6 +1,7 @@
import P, { pino } from "../../";
import { IncomingMessage, ServerResponse } from "http";
import { Socket } from "net";
import Logger = P.Logger;

const log = pino();
const info = log.info;
Expand Down Expand Up @@ -92,7 +93,7 @@ child.level = "info";
child.info("hooray");
log.info("nope nope nope");
log.child({ foo: "bar" }, { level: "debug" }).debug("debug!");
child.bindings();
(child as Logger).bindings();
const customSerializers = {
test() {
return "this is my serializer";
Expand All @@ -106,7 +107,7 @@ childRedacted.info({
msg: "logged with redacted properties",
path: "Not shown",
});
const childAnotherRedacted = pino().child({}, {
const childAnotherRedacted = pino().child({}, {
redact: {
paths: ["anotherPath"],
censor: "Not the log you\re looking for",
Expand Down Expand Up @@ -267,3 +268,7 @@ const logLine: pino.LogDescriptor = {
time: new Date().getTime(),
aCustomProperty: true,
};

interface CustomLogger extends pino.Logger {
customMethod(msg: string, ...args: unknown[]): void;
}

0 comments on commit 4e6fb85

Please sign in to comment.