UNPKG

1.59 kBPlain TextView Raw
1import winston = require('winston');
2
3function getLogger(): winston.LoggerInstance {
4 return new (winston.Logger)({
5 transports: [
6 new (winston.transports.Console)()
7 //,new (winston.transports.File)({ filename: 'nodedataLog.log', json: true})
8 ]
9 });
10}
11
12/**
13 * A wrapper around the winston logging framework.
14 */
15class WinstonLog {
16 winstonLogger = null;
17 logStream = null;
18 constructor() {
19 this.winstonLogger = getLogger();
20 var _logger = this.winstonLogger;
21 this.logStream = {
22 write : function(message, encoding){
23 _logger.debug(message);
24 }
25 }
26 }
27
28 /**
29 * Logs the message as info.
30 * @param message The message to be logged.
31 * @param meta Any additional metadata.
32 */
33 logInfo(message: any, meta? : any) {
34 this.winstonLogger.log('info', message, meta);
35 }
36
37 /**
38 * Logs the message as Debug
39 * @param message The message to be logged
40 * @param meta Any additional metadata
41 */
42 logDebug(message: any, meta? : any) {
43 this.winstonLogger.log('debug', message, meta);
44 }
45
46 /**
47 * Logs the message as Erro
48 * @param message The message to be logged
49 * @param meta Any additional metadata
50 */
51 logError(message: any, meta? : any) {
52 this.winstonLogger.log('error', message, meta);
53 }
54
55 configure(options:any){
56 this.winstonLogger.configure(options);
57 }
58
59 getStream(){
60 return this.logStream;
61 }
62}
63
64var winstonLog = new WinstonLog();
65export {winstonLog};
\No newline at end of file