File tree Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ import winston from 'winston' ;
2+
3+ const customLevels = {
4+ levels : {
5+ fatal : 0 ,
6+ error : 1 ,
7+ warning : 2 ,
8+ info : 3 ,
9+ http : 4 ,
10+ debug : 5 ,
11+ } ,
12+ colors : {
13+ fatal : 'magenta' ,
14+ error : 'red' ,
15+ warning : 'yellow' ,
16+ info : 'green' ,
17+ http : 'cyan' ,
18+ debug : 'blue' ,
19+ }
20+ } ;
21+
22+ winston . addColors ( customLevels . colors ) ;
23+
24+ const devLogger = winston . createLogger ( {
25+ levels : customLevels . levels ,
26+ level : 'debug' ,
27+ transports : [
28+ new winston . transports . Console ( {
29+ format : winston . format . combine (
30+ winston . format . colorize ( { all : true } ) ,
31+ winston . format . simple ( )
32+ )
33+ } )
34+ ]
35+ } ) ;
36+
37+ const prodLogger = winston . createLogger ( {
38+ levels : customLevels . levels ,
39+ level : 'info' ,
40+ transports : [
41+ new winston . transports . Console ( {
42+ format : winston . format . combine (
43+ winston . format . timestamp ( ) ,
44+ winston . format . json ( )
45+ )
46+ } ) ,
47+ new winston . transports . File ( {
48+ filename : 'errors.log' ,
49+ level : 'error' ,
50+ format : winston . format . json ( )
51+ } )
52+ ]
53+ } ) ;
54+
55+ const logger = process . env . NODE_ENV === 'production' ? prodLogger : devLogger ;
56+
57+ export default logger ;
You can’t perform that action at this time.
0 commit comments