-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from Jalle19/debug-logging
Refactor logging completely
- Loading branch information
Showing
12 changed files
with
4,058 additions
and
588 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"no-console": "error" | ||
} | ||
} |
This file contains 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 file contains 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 file contains 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 file contains 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 file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import winston from 'winston' | ||
|
||
const DEFAULT_LOG_LEVEL = 'info' | ||
|
||
// Define log transports here so we can change the log level later | ||
let transports = [new winston.transports.Console()] | ||
|
||
const logFormat = winston.format.printf(({ level, message, label, timestamp }) => { | ||
return `${timestamp} [${label}] ${level}: ${message}` | ||
}) | ||
|
||
export const setLogLevel = (logger, level) => { | ||
logger.info(`Setting log level to ${level}`) | ||
transports[0].level = level | ||
} | ||
|
||
export const createLogger = (module) => { | ||
return winston.createLogger({ | ||
'level': DEFAULT_LOG_LEVEL, | ||
'format': winston.format.combine( | ||
winston.format.label({ label: module }), | ||
winston.format.timestamp(), | ||
logFormat | ||
), | ||
'transports': transports, | ||
}) | ||
} |
Oops, something went wrong.