This repository has been archived by the owner on Jan 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
simple.jl
103 lines (81 loc) · 2.83 KB
/
simple.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#==
Run example with default log level:
>julia simple.jl
Run example with elevated log level:
>LOG4JL_DEFAULT_STATUS_LEVEL=ALL julia simple.jl
==#
module X
println("Current:", current_module())
# println("Current:", module_parent(current_module()))
using Log4jl
@Log4jl logger = @logger
module Y
println("Current:", current_module())
using Log4jl
@Log4jl logger = @logger(URI="log4jl.json")
Log4jl.level!(logger, Log4jl.Level.WARN)
module Z
println("Current:", current_module())
using Log4jl
@Log4jl logger = @Log4jl.logger begin
# Create a configuration for the logger
cfg = Log4jl.DefaultConfiguration()
# Add an appender to the configuration
Log4jl.appender!(cfg, OUTPUT = Log4jl.Appenders.Console(
layout = Log4jl.Layouts.PatternLayout("%d{%Y-%m-%d %H:%M:%S} [%t] %-5p %l %c{3} - %m%n")
))
# Add logger configuration with the name of the logger (i.e. "X.Y.Z")
#Log4jl.logger!(cfg, "X.Y.Z", Log4jl.LoggerConfig("LWC", Log4jl.Level.WARN))
Log4jl.logger!(cfg, "X.Y.Z", Log4jl.Level.WARN)
# Reference the appender in the logger configuration
Log4jl.reference!(cfg, "X.Y.Z" => "OUTPUT")
return cfg
end
println(logger)
println(logger.config)
function test_log3()
fatal(logger, "L3: fatal {}", 5)
@fatal "L3: FATAL {}" 5
@debug "L3: DEBUG {}" 1
@warn "L3: WARN {}" 3
@info "L3: INFO {}" 2
@debug "L3: DEBUG"
trace(logger, "L3: TRACE")
end
end
function test_log2()
Y.Z.test_log3()
@trace "L2: TRACE"
@debug "L2: DEBUG"
@info "L2: INFO {}" 2
@warn "L2: WARN {}" 3
@error "L2: ERROR {}" 4
@fatal "L2: FATAL {}" 5
end
end
function test_log1()
Y.test_log2()
trace(logger, "aaaaa")
debug(logger, "bbbbb {}", 1)
info(logger, "ccccc {}", 2)
@warn "ddddd {}" 3
sleep(1.)
fatal(logger, "fffff {}", 5)
error(logger, "eeeee {}", 4)
Log4jl.verbose(logger, "vvvvv {}", 6)
end
end
println("Current:", current_module())
println("Registered contexts:")
for (ctxname, ctx) in Log4jl.contexts(Log4jl.LOG4JL_CONTEXT_SELECTOR)
println("\t$ctxname => $ctx")
for (lgrname, lgr) in ctx.loggers
# lgr2 = Log4jl.logger(ctx, lgrname)
println("\t\t$lgrname => $lgr")
println("\t\t\t$(lgr.config) => $(Log4jl.references(lgr.config))")
end
end
println()
X.test_log1()
println("END\n")
xdump(X.logger)