Created
December 19, 2022 20:47
-
-
Save vduseev/79adb305bd601fbf60ef897b949e6036 to your computer and use it in GitHub Desktop.
JSON logging configuration for JavaScript using log4js (python compatible)
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
| /** | |
| * This configuration uses log4js and outputs logs to stdout | |
| * in JSON format. The names of the fields are compatible with | |
| * python-json-logger. | |
| * | |
| * The configuration was developed to the purposes of logging | |
| * Express JS logs running inside docker and collected through | |
| * FluentD. | |
| * | |
| * Reported fields: | |
| * name: my.logger | |
| * level: INFO | |
| * message: ekrjgnwle | |
| * timestamp: %Y-%m-%dT%H:%M:%S.%N%z | |
| */ | |
| const log4js = require("log4js"); | |
| log4js.configure({ | |
| appenders: { | |
| stdout: { | |
| type: "stdout", | |
| layout: { | |
| type: "pattern", | |
| //pattern: `{"timestamp": "%d{yyyy-MM-ddThh:mm:ss.SSSO}", "name": "%c", "level": "%p", "message": "%m{0}"}`, | |
| pattern: `{"timestamp": "%d{ISO8601_WITH_TZ_OFFSET}", "name": "%c", "level": "%p", "message": "%m{0}"}`, | |
| }, | |
| }, | |
| }, | |
| categories: { | |
| default: { appenders: ["stdout"], level: "info" }, | |
| }, | |
| }); | |
| exports.logger = log4js.getLogger("server"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment