-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.ts
46 lines (37 loc) · 1.08 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
import * as fs from 'fs'
function getTimeString() {
let str: String = ""
let date = new Date()
if (date.getHours() < 10) { str += "0" }
str += date.getHours().toString()
str += ":"
if (date.getMinutes() < 10) { str += "0" }
str += date.getMinutes().toString()
str += ":"
if (date.getSeconds() < 10) { str += "0" }
str += date.getSeconds().toString()
return str
}
var debugtf: Boolean
export function init(config: any) {
debugtf = config.debuglog // 是否输出调试日志
}
export function debug(t: any, p: String) {
if (debugtf) {
console.log(`[${getTimeString()}] [${p}/DEBUG]: ${t}`)
}
}
export function info(t: any, p: String) {
console.log(`[${getTimeString()}] [${p}/INFO]: ${t}`)
}
export function warn(t: any, p: String) {
console.log(`[${getTimeString()}] [${p}/WARN]: ${t}`)
}
export function error(t: any, p: String) {
if (t instanceof Error) {
console.log(`[${getTimeString()}] [${p}/ERROR]:`)
console.log(t)
} else {
console.log(`[${getTimeString()}] [${p}/ERROR]: ${t}`)
}
}