-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.sj
More file actions
59 lines (49 loc) · 1.45 KB
/
log.sj
File metadata and controls
59 lines (49 loc) · 1.45 KB
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
enum logLevel(
trace
debug
info
warn
error
fatal
)
log_includeAll : empty'hash![type, bool]
log_excludeAll : valid(hash![type, bool]())
log(
minLevel := logLevel.warn
traceIncludes := log_includeAll
debugIncludes := log_includeAll
infoIncludes := log_includeAll
warnIncludes := log_includeAll
errorIncludes := log_includeAll
fatalIncludes := log_includeAll
trace(t : 'type, cb : '()string) {
_write(logLevel.trace, traceIncludes, t, cb)
}
debug(t : 'type, cb : '()string) {
_write(logLevel.debug, debugIncludes, t, cb)
}
info(t : 'type, cb : '()string) {
_write(logLevel.info, infoIncludes, t, cb)
}
warn(t : 'type, cb : '()string) {
_write(logLevel.warn, warnIncludes, t, cb)
}
error(t : 'type, cb : '()string) {
_write(logLevel.error, errorIncludes, t, cb)
}
fatal(t : 'type, cb : '()string) {
_write(logLevel.fatal, fatalIncludes, t, cb)
}
_write(level : 'logLevel, includes : 'hash?![type, bool], t : 'type, cb : '()string) {
if level >= minLevel {
ifValid includes {
if includes[t]?:false {
debug.writeLine(level.asString().toUpperCase() + " [" + t.asString() + "] " + cb())
}
} elseEmpty {
debug.writeLine(level.asString().toUpperCase() + " [" + t.asString() + "] " + cb())
}
}
}
) { this }
log : log()