-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLog.jl
43 lines (33 loc) · 1000 Bytes
/
Log.jl
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
module Log
export pssfss_logger, ScreenLevel, FileLevel, @logfile, @logscreen
using Logging: LogLevel, global_logger, @logmsg
using LoggingExtras: FormatLogger, TeeLogger, EarlyFilteredLogger
const ScreenLevel = LogLevel(-500)
const FileLevel = LogLevel(-400)
macro logscreen(x)
:(@logmsg(ScreenLevel, $(esc(x))))
end
macro logfile(x)
:(@logmsg(FileLevel, $(esc(x))))
end
function newlevels_filter(log_args)
log_args.level ∈ (FileLevel, ScreenLevel)
end
function notnew_filter(log_args)
log_args.level ∉ (ScreenLevel, FileLevel)
end
function plain_logger(logfile)
isfile(logfile) && rm(logfile)
FormatLogger() do io, args
open(logfile, "a") do f
println(f, args.message)
end
args.level == ScreenLevel && println(args.message)
end
end
pssfss_logger(logfile) =
TeeLogger(
EarlyFilteredLogger(notnew_filter, global_logger()),
EarlyFilteredLogger(newlevels_filter, plain_logger(logfile))
)
end # module