Skip to content

Instantly share code, notes, and snippets.

@vanduc1102
Created May 2, 2024 09:26
Show Gist options
  • Save vanduc1102/bdc737c05041ecfcce34cd23f4d6ada2 to your computer and use it in GitHub Desktop.
Save vanduc1102/bdc737c05041ecfcce34cd23f4d6ada2 to your computer and use it in GitHub Desktop.
nodejs pino typescript configuration example
// npm i -S pino
// npm i -D pino-pretty
import pino from "pino";
const { LOG_LEVEL = "debug", APP_NAME = "Web" } = process.env;
const isProduction = process.env.NODE_ENV === "production";
const logger = pino({
name: APP_NAME,
level: LOG_LEVEL,
...(!isProduction && {
transport: {
target: "pino-pretty",
options: {
colorize: true,
levelFirst: true,
translateTime: true,
},
},
}),
});
/**
*
* @param module for categorizing log messages
* @returns
*/
export default function getLogger(module = "") {
if (!module) {
return logger;
}
return logger.child({
module,
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment