Created
May 14, 2017 23:17
-
-
Save z3t0/f910e750d37149412b2b1532f1044488 to your computer and use it in GitHub Desktop.
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
let winston = require('winston') | |
class Logger { | |
name: string | |
logger: any | |
constructor(opts: { name: string }) { | |
this.name = name | |
var myCustomLevels = { | |
levels: { | |
error: 0, | |
warn: 1, | |
info: 2, | |
modLoader: 3, | |
mods: 4, | |
debug: 5 | |
}, | |
colors: { | |
error: 'red', | |
warn: 'yellow', | |
info: 'magenta', | |
modLoader: 'blue', | |
mods: 'blue', | |
debug: 'green' | |
} | |
} | |
// Winston | |
const tsFormat = () => (new Date()).toLocaleTimeString() | |
this.logger = new (winston.Logger)({ | |
levels: myCustomLevels.levels, | |
transports: [ | |
// colorize the output to the console | |
new (winston.transports.Console)({ | |
timestamp: tsFormat, | |
colorize: true | |
}) | |
] | |
}) | |
winston.addColors(myCustomLevels.colors) | |
this.logger.level = 'debug' | |
this.logger.info('Initialised Logger') | |
} | |
info(msg : string) { | |
this.logger.info(msg) | |
} | |
warn(msg : string) { | |
this.logger.warn(msg) | |
} | |
error(msg : string) { | |
this.logger.error(msg) | |
} | |
modLoader(msg : string) { | |
this.logger.modLoader(msg) | |
} | |
mods(msg : string) { | |
this.logger.mods(msg) | |
} | |
debug(msg : string) { | |
this.logger.debug(msg) | |
} | |
} | |
module.exports = Logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment