forked from MicrosoftDX/Vorlonjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vorlon.winstonlogger.ts
81 lines (71 loc) · 2.68 KB
/
vorlon.winstonlogger.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import express = require("express");
import winston = require("winston");
import http = require("http");
//Vorlon
import iwsc = require("./vorlon.IWebServerComponent");
import tools = require("./vorlon.tools");
import vorloncontext = require("../config/vorlon.servercontext");
var winstonDisplay = require("winston-logs-display");
export module VORLON {
export class WinstonLogger implements iwsc.VORLON.IWebServerComponent {
private logConfig: vorloncontext.VORLON.ILogConfig;
private _log: winston.LoggerInstance;
constructor(context : vorloncontext.VORLON.IVorlonServerContext) {
this.logConfig = context.logConfig;
//LOGS
winston.cli();
this._log = new winston.Logger(<any>{
levels: {
info: 0,
warn: 1,
error: 2,
verbose: 3,
api: 4,
dashboard: 5,
plugin: 6
},
transports: [
new winston.transports.File(<any>{ filename: this.logConfig.vorlonLogFile, level: this.logConfig.level})
],
exceptionHandlers: [
new winston.transports.File(<any>{ filename: this.logConfig.exceptionsLogFile, timestamp: true, maxsize: 1000000 })
],
exitOnError: false
});
context.logger = this._log;
if (this.logConfig.enableConsole) {
this._log.add(winston.transports.Console, <any>{
level: this.logConfig.level,
handleExceptions: true,
json: false,
timestamp: function() {
var date:Date = new Date();
return date.getFullYear() + "-" +
date.getMonth() + "-" +
date.getDate() + " " +
date.getHours() + ":" +
date.getMinutes() + ":" +
date.getSeconds();
},
colorize: true
});
}
winston.addColors({
info: 'green',
warn: 'cyan',
error: 'red',
verbose: 'blue',
api: 'gray',
dashboard: 'pink',
plugin: 'yellow'
});
this._log.cli();
}
public addRoutes(app: express.Express, passport: any): void {
//DisplayLogs
winstonDisplay(app, this._log);
}
public start(httpServer: http.Server): void {
}
}
}