From 52834139f1eef5804a353db053b6a1021c9917dd Mon Sep 17 00:00:00 2001 From: Art Wild Date: Tue, 28 Apr 2015 11:50:47 -0400 Subject: [PATCH 1/3] new loggers inherit `root` logger properties plus compatibility and trailing spaces fix --- src/Logging.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Logging.jl b/src/Logging.jl index efb0bb9e..928b2eb0 100644 --- a/src/Logging.jl +++ b/src/Logging.jl @@ -2,7 +2,7 @@ module Logging using Compat -import Base: show +import Base: show, info, warn export debug, info, warn, err, critical, log, @debug, @info, @warn, @err, @error, @critical, @log, @@ -31,13 +31,13 @@ type Logger Logger(name::String, level::LogLevel, output::IO) = (x = new(); x.name = name; x.level=level; x.output=output; x.parent=x) end -show(io::IO, logger::Logger) = print(io, "Logger(", join([logger.name, - logger.level, +show(io::IO, logger::Logger) = print(io, "Logger(", join([logger.name, + logger.level, logger.output, logger.parent.name], ","), ")") const _root = Logger("root", WARNING, STDERR) -Logger(name::String;args...) = configure(Logger(name, WARNING, STDERR, _root); args...) +Logger(name::String;args...) = configure(Logger(name, _root.level, _root.output, _root); args...) Logger() = Logger("logger") for (fn,lvl,clr) in ((:debug, DEBUG, :cyan), @@ -70,7 +70,7 @@ function configure(logger=_root; args...) logger.output = parent.output end end - + for (tag, val) in args tag == :io ? (logger.output = val::IO) : tag == :output ? (logger.output = val::IO) : From 6526ff99e06b114b8572f610f9c1be0a4fe3cbbc Mon Sep 17 00:00:00 2001 From: Art Wild Date: Tue, 28 Apr 2015 12:01:29 -0400 Subject: [PATCH 2/3] added hierarchy tests --- test/hierarchy.jl | 30 ++++++++++++++++++++++++++++++ test/runtests.jl | 1 + 2 files changed, 31 insertions(+) create mode 100644 test/hierarchy.jl diff --git a/test/hierarchy.jl b/test/hierarchy.jl new file mode 100644 index 00000000..a090debf --- /dev/null +++ b/test/hierarchy.jl @@ -0,0 +1,30 @@ +module TestHierarchy + using Base.Test + using Logging + + # configre root logger + output = IOBuffer() + Logging.configure(level=DEBUG, io = output) + root = Logging._root + + loggerA = "levelA" + level1A = Logger(loggerA) + + loggerB = "levelB" + level1B = Logger(loggerB, level = INFO) + + logger2 = "level2" + level2 = Logger(logger2, parent=level1B) + + # test hierarchy + @test root.parent == root + @test level1A.parent == root + @test level1A.parent == root + @test level2.parent == level1B + + # test properties + @test level1A.level == root.level + @test level1B.level == INFO + @test level2.level == level1B.level + +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 3c8e2652..b0564b32 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,3 +2,4 @@ include("log_test.jl") include("macro_test1.jl") include("macro_test2.jl") include("macro_test3.jl") +include("hierarchy.jl") From 6b879acc7b5788fec9a4c8b4a6934de277f14ea6 Mon Sep 17 00:00:00 2001 From: Art Wild Date: Tue, 28 Apr 2015 14:27:38 -0400 Subject: [PATCH 3/3] docs update --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index f0ac7a2f..e42d643f 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,22 @@ julia> son_logger = Logger("Son", parent=mum_logger); julia> son_logger.level INFO ``` +If during the logger creation the `parent` parameter is not specified +then the logger inherits all properties of the `root` logger +unless specified otherwise explicitly. + +```julia +julia> using Logging + +julia> Logging.configure(level=DEBUG) # root has DEBUG level +Logger(root,DEBUG,TTY(open, 0 bytes waiting),root) + +julia> logger1 = Logger("logger1") # logger1 has DEBUG level as well +Logger(logger1,DEBUG,TTY(open, 0 bytes waiting),root) + +julia> logger2 = Logger("logger2", level=INFO) # logger2 has INFO level +Logger(logger2,INFO,TTY(open, 0 bytes waiting),root) +``` Notes -----