1 | import { createLogger, transports, format } from 'winston'; |
||
2 | import arrayTransport from 'winston-array-transport'; |
||
3 | import { logsPath } from './constants'; |
||
4 | |||
5 | const levels = { |
||
6 | error : 0, |
||
7 | warn : 1, |
||
8 | info : 2, |
||
9 | notice : 3, |
||
10 | verbose : 4, |
||
11 | debug : 5 |
||
12 | }; |
||
13 | |||
14 | const JSONFormats = [ |
||
15 | format.splat(), |
||
16 | format.timestamp(), |
||
17 | format.json() |
||
18 | ]; |
||
19 | |||
20 | export const factoryLogger = createLogger({ |
||
21 | transports : [ |
||
22 | new transports.File({ |
||
23 | filename : logsPath |
||
24 | }) |
||
25 | ] |
||
26 | }); |
||
27 | |||
28 | export const apiTraces = []; |
||
29 | |||
30 | export const apiLogger = createLogger({ |
||
31 | level : 'debug', |
||
32 | levels, |
||
33 | format : format.combine(...JSONFormats), |
||
34 | transports : [ |
||
35 | new transports.Console(), |
||
36 | new transports.File({ |
||
37 | filename : logsPath |
||
38 | }), |
||
39 | new arrayTransport({ |
||
0 ignored issues
–
show
Coding Style
Best Practice
introduced
by
![]() |
|||
40 | array : apiTraces, |
||
41 | json : true |
||
42 | }) |
||
43 | ] |
||
44 | }); |
||
45 | |||
46 | export function createUnitLogger(level = 'verbose') { |
||
47 | const traces = []; |
||
48 | const logger = createLogger({ |
||
49 | level, |
||
50 | levels, |
||
51 | format : format.combine(...JSONFormats), |
||
52 | transports : [ |
||
53 | new arrayTransport({ |
||
0 ignored issues
–
show
|
|||
54 | array : traces, |
||
55 | json : true |
||
56 | }) |
||
57 | ] |
||
58 | }); |
||
59 | |||
60 | return { logger, traces }; |
||
61 | } |
||
62 |