Created
May 2, 2024 09:26
-
-
Save vanduc1102/bdc737c05041ecfcce34cd23f4d6ada2 to your computer and use it in GitHub Desktop.
nodejs pino typescript configuration example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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