File tree 1 file changed +43
-0
lines changed
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { formatDate } from 'helpers/Date'
2
+ import path from 'path'
3
+ import winston from 'winston'
4
+
5
+ // define the custom settings for each transport (file, console)
6
+ const options = {
7
+ file : {
8
+ level : 'info' ,
9
+ filename : `${ path . resolve ( './logs' ) } /log-${ formatDate ( new Date ( ) ) } .log` ,
10
+ handleExceptions : true ,
11
+ json : true ,
12
+ maxsize : 5242880 , // 5MB
13
+ maxFiles : 5 ,
14
+ colorize : false ,
15
+ } ,
16
+ console : {
17
+ level : 'debug' ,
18
+ handleExceptions : true ,
19
+ json : false ,
20
+ colorize : true ,
21
+ } ,
22
+ }
23
+
24
+ // instantiate a new Winston Logger with the settings defined above
25
+ const winstonLogger = winston . createLogger ( {
26
+ format : winston . format . json ( ) ,
27
+ transports : [
28
+ //
29
+ // - Write all logs with level `error` and below to `error.log`
30
+ // - Write all logs with level `info` and below to `combined.log`
31
+ //
32
+ new winston . transports . File ( options . file ) ,
33
+ new winston . transports . Console ( options . console ) ,
34
+ ] ,
35
+ exitOnError : false ,
36
+ } )
37
+
38
+ // create a stream object with a 'write' function that will be used by `morgan`
39
+ export const winstonStream = {
40
+ write : ( message : string ) => {
41
+ winstonLogger . info ( message )
42
+ } ,
43
+ }
You can’t perform that action at this time.
0 commit comments