-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add --debug flag and some refactoring related to that
- Loading branch information
Showing
3 changed files
with
29 additions
and
9 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
function debug(): boolean { | ||
return typeof process.env.DEBUG === 'string' || process.env.LOG_LEVEL === 'DEBUG'; | ||
return process.env.LOG_LEVEL === 'DEBUG' || process.env.DEBUG !== undefined; | ||
} | ||
export default debug; |
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 |
---|---|---|
@@ -1,13 +1,25 @@ | ||
import * as process from 'process'; | ||
import * as _ from 'lodash'; | ||
import * as winston from 'winston'; | ||
import debug from './debug'; | ||
|
||
export const logger = new winston.Logger({ | ||
transports: [ | ||
new winston.transports.Console({ | ||
let LOG_LEVEL: string; | ||
if (debug()) { | ||
LOG_LEVEL = 'debug'; | ||
} else { | ||
LOG_LEVEL = _.get(process.env, 'LOG_LEVEL', 'info').toLowerCase(); | ||
} | ||
|
||
const consoleLogger = new winston.transports.Console({ | ||
colorize: true, | ||
level: _.get(process.env, 'LOG_LEVEL', 'info'), | ||
level: LOG_LEVEL, | ||
prettyPrint: true | ||
}) | ||
] | ||
}); | ||
|
||
export function setLogLevel(level: string) { | ||
consoleLogger.level = level; | ||
} | ||
|
||
export const logger = new winston.Logger({ | ||
transports: [consoleLogger] | ||
}); |