Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pino-caller support #15

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ prettyPrint | boolean |false| pretty print for developing purposes
redact | array | undefined| array of paths in object to be redacted from the log
destination | number / string | 1 | The stream to send the log to, or file
base | object | {pid: process.pid, hostname: os.hostname} | Key-value object added as child logger to each log line
pinoCaller | boolean | false | adds the call site of each log message to the log output
36 changes: 27 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
},
"dependencies": {
"pino": "^8.11.0",
"pino-caller": "^3.4.0",
"pino-pretty": "^10.0.0"
}
}
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pino, { LoggerOptions as PinoOptions, Logger, TransportSingleOptions } from 'pino';
import pinoCaller from 'pino-caller';

type LoggerOptions = Pick<PinoOptions, 'enabled' | 'level' | 'redact' | 'hooks' | 'base' | 'mixin'> & { prettyPrint?: boolean };
type LoggerOptions = Pick<PinoOptions, 'enabled' | 'level' | 'redact' | 'hooks' | 'base' | 'mixin'> & { prettyPrint?: boolean; pinoCaller?: boolean };

const baseOptions: PinoOptions = {
formatters: {
Expand All @@ -20,7 +21,13 @@ const jsLogger = (options?: LoggerOptions, destination: string | number = 1): Lo
}

const pinoOptions: PinoOptions = { ...baseOptions, ...options, transport };
return pino(pinoOptions, pino.destination(destination));
const logger = pino(pinoOptions, pino.destination(destination));

if (options?.pinoCaller === true) {
return pinoCaller(logger);
}

return logger;
};

export { Logger } from 'pino';
Expand Down
Loading