Skip to content

Commit 7496182

Browse files
authored
Merge pull request #6 from colinfang/dev
Dev
2 parents 2e53ae4 + 2400879 commit 7496182

File tree

7 files changed

+78
-10
lines changed

7 files changed

+78
-10
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ os:
44
- linux
55
- osx
66
julia:
7-
- 0.5
87
- 0.6
9-
- nightly
108
notifications:
119
email: false

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
julia 0.5
1+
julia 0.5 0.7-

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This is a Julia equivalent of Python logging package. It provides a basic hierar
88

99
## Why another logging package?
1010

11-
When dealing with multple nested modules, the experience with the exising Julia `logging.jl` package isn't very nice.
11+
When dealing with multiple nested modules, the experience with the existing Julia `logging.jl` package isn't very nice.
1212

1313
- To keep a logger hierarchy, I have to explicitly pass in a parent logger which might not exist yet.
1414
- To change the current logging level, I have to find all descendant loggers and explicitly set them.

test/runtests.jl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,20 @@ push!(t, "")
3838
@test parent_node(t, "") == ""
3939

4040

41-
basic_config(MiniLogging.INFO)
42-
logger = get_logger("a.b")
43-
@info(logger, "Hello", " world", )
44-
@debug(logger, "Hello", " world", error("no error"))
41+
open("stdout.out", "w") do f1
42+
open("stderr.out", "w") do f2
43+
redirect_stdout(f1) do
44+
redirect_stderr(f2) do
45+
include("test_log.jl")
46+
end
47+
end
48+
end
49+
end
4550

46-
MiniLogging.define_new_level(:trace, 25, :yellow)
47-
@trace(logger, "Hello", " world")
51+
out1 = readlines("stdout.log")
52+
err1 = readlines("stderr.log")
53+
out2 = readlines("stdout.out")
54+
err2 = readlines("stderr.out")
55+
56+
@test out1 == out2
57+
@test err1 == err2

test/stderr.log

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:WARN:Main:Hello world
2+
:INFO:a.b:Hello world
3+
:DEBUG:a.b.c:Hello world
4+
:trace:a.b:Hello world

test/stdout.log

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
RootLogger(WARN:30)
2+
RootLogger(WARN:30)
3+
RootLogger(INFO:20)
4+
Logger("a.b", NOTSET:0)
5+
ErrorException("has error")
6+
Logger("a.b.c", NOTSET:0)

test/test_log.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Get root logger.
2+
# Nothing appears as we haven't set any config on any loggers.
3+
root_logger = get_logger()
4+
println(root_logger)
5+
6+
# This is also root logger.
7+
println(get_logger(""))
8+
9+
# Set root config.
10+
# It inserts a handler that outputs message to `STDERR`.
11+
basic_config(MiniLogging.INFO, date_format="")
12+
13+
# It changes the root logger level.
14+
get_logger("")
15+
println(root_logger)
16+
17+
@warn(root_logger, "Hello", " world")
18+
19+
# Get a logger.
20+
logger = get_logger("a.b")
21+
println(logger)
22+
23+
# Since the level of `logger` is unset, it inherits its nearest ancestor's level.
24+
# Its effective level is `INFO` (from `root_logger`) now.
25+
@info(logger, "Hello", " world")
26+
27+
# Since `DEBUG < INFO`, no message is generated.
28+
# Note the argument expressions are not evaluated in this case to increase performance.
29+
@debug(logger, "Hello", " world", error("no error"))
30+
31+
# Explicitly set the level.
32+
# The error is triggered.
33+
logger.level = MiniLogging.DEBUG
34+
try
35+
@debug(logger, "Hello", " world", error("has error"))
36+
catch e
37+
println(e)
38+
end
39+
40+
# Get a child logger.
41+
logger2 = get_logger("a.b.c")
42+
println(logger2)
43+
44+
# Its effective level now is `DEBUG` (from `logger`) now.
45+
@debug(logger2, "Hello", " world")
46+
47+
# Add A New Level
48+
MiniLogging.define_new_level(:trace, 25, :yellow)
49+
@trace(logger, "Hello", " world")
50+

0 commit comments

Comments
 (0)