This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.ts
79 lines (77 loc) · 3.06 KB
/
logger.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
import * as winston from 'winston';
import { sendLog } from './util/discordLogger';
import { format as prettyFormat } from 'pretty-format';
const colorizer = winston.format.colorize();
export const logger = winston.createLogger({
levels: {
error: 0,
warn: 1,
info: 2,
dapi: 3,
cmd: 4,
btn: 4,
self: 5,
db: 6,
http: 8,
verbose: 9,
debug: 10,
silly: 11,
},
transports: [
new winston.transports.Console({
level: `debug`,
handleExceptions: true,
format: winston.format.combine(
winston.format.timestamp(),
winston.format.simple(),
winston.format.printf(msg => {
sendLog(msg)
const message = msg.message || msg.command || msg.button || `?`
return `${colorizer.colorize('verbose', `[${`${msg.timestamp}`.replace(/[T]/, ` `).replace(/[Z]/, ``)}]`)} ${colorizer.colorize([`cmd`, `btn`].includes(msg.level) ? `info` : msg.level, `[${msg.level.toUpperCase()}]`)
} ${typeof message === 'string' ? message : prettyFormat(message, {
indent: 8,
printBasicPrototype: false,
printFunctionName: true,
})}`
})
),
}),
new winston.transports.File({
level: `debug`,
handleExceptions: true,
filename: `./logs/debug.log`,
maxsize: 5242880, // 5MB,
format: winston.format.combine(
winston.format.timestamp(),
winston.format.simple(),
winston.format.printf(msg => {
const message = msg.message || msg.command || msg.button || `?`
return `[${`${msg.timestamp}`.replace(/[T]/, ` `).replace(/[Z]/, ``)}] [${msg.level.toUpperCase()}] ${typeof message === 'string' ? message : prettyFormat(message, {
indent: 8,
printBasicPrototype: false,
printFunctionName: true,
})}`
})
),
}),
new winston.transports.File({
level: `btn`,
handleExceptions: true,
filename: `./logs/application.log`,
maxsize: 5242880, // 5MB
format: winston.format.combine(
winston.format.timestamp(),
winston.format.simple(),
winston.format.printf(msg => {
const message = msg.message || msg.command || msg.button || `?`
return `[${`${msg.timestamp}`.replace(/[T]/, ` `).replace(/[Z]/, ``)}] [${msg.level.toUpperCase()}] ${typeof message === 'string' ? message : prettyFormat(message, {
indent: 8,
printBasicPrototype: false,
printFunctionName: true,
})}`
})
),
}),
],
exitOnError: false,
})