-
Notifications
You must be signed in to change notification settings - Fork 2
/
logger.js
59 lines (54 loc) · 1.29 KB
/
logger.js
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
/***
*
* NPM logging levels = {
error: 0,
warn: 1,
info: 2,
http: 3,
verbose: 4,
debug: 5,
silly: 6
}
*
*/
import * as winston from 'winston'
// import { createLogger, format, transports } from 'winston'
import 'winston-daily-rotate-file'
// const LEVEL = process.env.NODE_ENV === 'production' ? 'info' : 'verbose'
const ERROR_LOG = './logs/errors-%DATE%.log'
const CONSOLE_LEVEL =
process.env.CONSOLE_LOGGER_LEVEL ||
(process.env.NODE_ENV === 'production' ? 'warn' : 'verbose')
const errorRotation = new winston.transports.DailyRotateFile({
filename: ERROR_LOG,
datePattern: 'YYYY-MM-DD-HH',
zippedArchive: true,
maxFiles: '1d',
level: 'error',
})
const logger = winston.createLogger({
// level: LEVEL,
format: winston.format.combine(
winston.format.timestamp({
format: 'DD-MM-YYYY HH:mm:ss',
}),
winston.format.errors({ stack: true }),
winston.format.splat(),
winston.format.json()
),
defaultMeta: {
site: process.env.SITE_HOST,
drupal: process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
},
transports: [
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
),
level: CONSOLE_LEVEL,
}),
errorRotation,
],
})
export default logger