From 44bc42cf608edd0a67d235a4529f74eee96d2a14 Mon Sep 17 00:00:00 2001 From: Kevin Squire Date: Fri, 7 Oct 2016 10:39:56 -0700 Subject: [PATCH 01/10] Deprecate Logging.err --- src/Logging.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Logging.jl b/src/Logging.jl index e2c24d95..695e9adb 100644 --- a/src/Logging.jl +++ b/src/Logging.jl @@ -116,6 +116,8 @@ for (fn,lvl,clr) in ((:debug, DEBUG, :cyan), end +@deprecate err Logging.error + function configure(logger=_root; args...) for (tag, val) in args if tag == :parent From 01d1520ec2df61029484ff73068ed0979ffe7fe8 Mon Sep 17 00:00:00 2001 From: Kevin Squire Date: Thu, 6 Oct 2016 21:37:04 -0700 Subject: [PATCH 02/10] Unexport logging functions --- README.md | 51 +++----------------- src/Logging.jl | 117 +++++++++++++++++++++++++++++++++++++-------- test/log_test.jl | 11 ++--- test/macro_test.jl | 26 +++++++++- test/runtests.jl | 1 - 5 files changed, 133 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index 68f3ff53..5ea7ab23 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,11 @@ using Logging # Logging.configure(level=WARNING) function log_test() - debug("debug message") - info("info message") - warn("warning message") - err("error message") - critical("critical message") + Logging.debug("debug message") + Logging.info("info message") + Logging.warn("warning message") + Logging.err("error message") + Logging.critical("critical message") end println("Setting level=DEBUG") @@ -235,44 +235,5 @@ julia> mum_logger = Logger("Mum"); julia> Logging.configure(mum_logger, level=INFO); julia> son_logger = Logger("Son", parent=mum_logger); julia> son_logger.level -INFO -``` - -Notes ------ -* By default, `Logging.info` masks `Base.info`. However, if `Base.info` is called before - `using Logging`, `info` will always refer to the `Base` version. - - ```julia -julia> info("Here's some info.") -INFO: Here's some info. - -julia> using Logging -Warning: using Logging.info in module Main conflicts with an existing identifier. - -julia> @Logging.configure(level=Logging.INFO) -Logger(root,INFO,TTY(open, 0 bytes waiting),root) - -julia> info("Still using Base.info") -INFO: Still using Base.info - -julia> Logging.info("You can still fully qualify Logging.info.") -17-Jan 13:19:56:INFO:root:You can still fully qualify Logging.info. -``` - - If this is not desirable, you may call `@Logging.configure` with `override_info=true`: - - ```julia -julia> info("Here's some info again.") -INFO: Here's some info again. - -julia> using Logging -Warning: using Logging.info in module Main conflicts with an existing identifier. - -julia> @Logging.configure(level=Logging.INFO, override_info=true) -Warning: Method definition info(AbstractString...,) in module Base at util.jl:216 overwritten in module Main at /Users/kevin/.julia/v0.4/Logging/src/Logging.jl:85. -Logger(root,INFO,TTY(open, 0 bytes waiting),root) - -julia> info("Now we're using Logging.info") -17-Jan 13:17:20:INFO:root:Now we're using Logging.info +INFO::Logging.LogLevel = 6 ``` diff --git a/src/Logging.jl b/src/Logging.jl index 695e9adb..15f682fa 100644 --- a/src/Logging.jl +++ b/src/Logging.jl @@ -2,11 +2,7 @@ __precompile__() module Logging -import Base: show, info, warn - -export debug, info, warn, err, critical, - @debug, @info, @warn, @err, @error, @critical, @log, - Logger, +export Logger, LogLevel, DEBUG, INFO, WARNING, ERROR, CRITICAL, OFF, LogFacility, SysLog @@ -72,10 +68,10 @@ type Logger Logger{T<:LogOutput}(name::AbstractString, level::LogLevel, output::Array{T,1}) = (x = new(); x.name = name; x.level=level; x.output=output; x.parent=x) end -show(io::IO, logger::Logger) = print(io, "Logger(", join(Any[logger.name, - logger.level, - logger.output, - logger.parent.name], ","), ")") +Base.show(io::IO, logger::Logger) = print(io, "Logger(", join(Any[logger.name, + logger.level, + logger.output, + logger.parent.name], ","), ")") const _root = Logger("root", WARNING, STDERR) Logger(name::AbstractString;args...) = configure(Logger(name, WARNING, STDERR, _root); args...) @@ -101,7 +97,7 @@ end for (fn,lvl,clr) in ((:debug, DEBUG, :cyan), (:info, INFO, :blue), (:warn, WARNING, :magenta), - (:err, ERROR, :red), + (:error, ERROR, :red), (:critical, CRITICAL, :red)) @eval function $fn(logger::Logger, msg...) @@ -113,12 +109,11 @@ for (fn,lvl,clr) in ((:debug, DEBUG, :cyan), end @eval $fn(msg...) = $fn(_root, msg...) - end @deprecate err Logging.error -function configure(logger=_root; args...) +function _configure(logger=_root; args...) for (tag, val) in args if tag == :parent logger.parent = parent = val::Logger @@ -136,26 +131,108 @@ function configure(logger=_root; args...) tag == :level ? (logger.level = val::LogLevel) : tag == :override_info ? nothing : # handled below tag == :parent ? nothing : # handled above - (Base.error("Logging: unknown configure argument \"$tag\"")) + (throw(ArgumentError("Logging: unknown configure argument \"$tag\""))) end logger end -override_info(;args...) = (:override_info, true) in args +""" +Module which contains versions of the logging functions which +print a deprecation warning when used. + +This is useful for transitioning users to either call the qualified +function names (e.g., `Logging.info`, `Logging.warn`, etc.) or explicitly +import the functions. +""" +module _Deprecated + +import Logging + +deprecation_printed = false + +for fn in (:debug, :info, :warn, :error, :critical) + @eval function $fn(args...) + global deprecation_printed + if !deprecation_printed + Base.warn(""" + In the future, `using Logging` will not import the following + logging functions: + + debug + info + warn + error + critical + + You can either use these functions by qualifying them + (e.g., `Logging.debug(...)`, `Logging.warn(...)`, etc.), + or by explicitly importing them: + + using Logging + import Logging: debug, info, warn, error, critical + + """) + deprecation_printed = true + end + + Logging.$fn(args...) + end +end + +end # module _Deprecated + +function _imported_with_using() + return all(isdefined.(names(Logging))) +end + +function _logging_funcs_imported() + # isdefined "reifies" any object that is defined, making it impossible + # it to override it via import. Therefore, we don't check + # `info`, `warn`, and `error`, since these functions exist in + # Base and won't be overridden if we check them here. + return all(isdefined.([:debug, #=:info, :warn, :error,=# :critical])) +end + +let _macros_loaded = false + global macros_loaded, set_macros_loaded + macros_loaded() = _macros_loaded + set_macros_loaded() = (_macros_loaded = true) +end + +_src_dir = dirname(@__FILE__) macro configure(args...) - _args = gensym() quote - logger = Logging.configure($(args...)) - if Logging.override_info($(args...)) - function Base.info(msg::AbstractString...) - Logging.info(Logging._root, msg...) + logger = Logging._configure($(args...)) + + if Logging._imported_with_using() && !Logging._logging_funcs_imported() + # We assume that the user has not manually + # imported the Logging functions, and we import + # versions of these which print a deprecation warning + try + import Logging._Deprecated: info, warn, debug, error, critical + catch + Base.warn("Please call Logging.@configure from the top level (module) scope.") end end - include(joinpath(Pkg.dir("Logging"), "src", "logging_macros.jl")) + + if !Logging.macros_loaded() + include(joinpath(Logging._src_dir, "logging_macros.jl")) + Logging.set_macros_loaded() + end logger end end +function configure(args...; kwargs...) + throw(ErrorException(""" + The functional form of Logging.configure(...) is no longer supported. + Instead, call + + Logging.@configure(...) + + """)) +end + end # module diff --git a/test/log_test.jl b/test/log_test.jl index 1c52b43e..f277096b 100644 --- a/test/log_test.jl +++ b/test/log_test.jl @@ -6,11 +6,11 @@ using Logging function log_test() println("\nTesting function calls:\n") - debug("debug message") - info("info message") - warn("warning message") - err("error message") - critical("critical message") + Logging.debug("debug message") + Logging.info("info message") + Logging.warn("warning message") + Logging.err("error message") + Logging.critical("critical message") end function log_test2() @@ -50,4 +50,3 @@ println("\nSetting level=CRITICAL") Logging.configure(level=CRITICAL) log_test() log_test2() - diff --git a/test/macro_test.jl b/test/macro_test.jl index f8f062fd..bfbe71b9 100644 --- a/test/macro_test.jl +++ b/test/macro_test.jl @@ -3,7 +3,7 @@ using Base.Test function test_log_macro_common(flags) for (macroname, isshown) in flags - ex = Expr(:macrocall, symbol(macroname), "test message") + ex = Expr(:macrocall, Symbol(macroname), "test message") if isshown @test ex |> macroexpand != :nothing else @@ -12,26 +12,50 @@ function test_log_macro_common(flags) end end +module TestDebug +using Logging +import ..test_log_macro_common @Logging.configure(level=DEBUG) test_log_macro_common([(:@debug, true), (:@info, true), (:@warn, true), (:@err, true), (:@critical, true)]) +end +module TestInfo +using Logging +import ..test_log_macro_common @Logging.configure(level=INFO) test_log_macro_common([(:@debug, false), (:@info, true), (:@warn, true), (:@err, true), (:@critical, true)]) +end +module TestWarning +using Logging +import ..test_log_macro_common @Logging.configure(level=WARNING) test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, true), (:@err, true), (:@critical, true)]) +end +module TestError +using Logging +import ..test_log_macro_common @Logging.configure(level=ERROR) test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, false), (:@err, true), (:@critical, true)]) +end +module TestCritical +using Logging +import ..test_log_macro_common @Logging.configure(level=CRITICAL) test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, false), (:@err, false), (:@critical, true)]) +end +module TestOff +using Logging +import ..test_log_macro_common @Logging.configure(level=OFF) test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, false), (:@err, false), (:@critical, false)]) +end diff --git a/test/runtests.jl b/test/runtests.jl index 6f60281b..d9cc0385 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,3 @@ -using Logging: debug, info, warn include("log_test.jl") include("macro_test.jl") include("test_hierarchy.jl") From 344c960fc6adf0209d56dac0debaecfb25558c41 Mon Sep 17 00:00:00 2001 From: Kevin Squire Date: Mon, 10 Oct 2016 10:22:33 -0700 Subject: [PATCH 03/10] Update .travis to only test on v0.5 and nightly --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5d308e7a..84a758fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ os: - linux - osx julia: - - 0.4 - 0.5 - nightly notifications: From fee041445f2268df705d10599932ca120941c437 Mon Sep 17 00:00:00 2001 From: Kevin Squire Date: Mon, 10 Oct 2016 10:23:35 -0700 Subject: [PATCH 04/10] Bump minimum julia version to v0.5 --- REQUIRE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/REQUIRE b/REQUIRE index d5d64671..94237c0f 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1 @@ -julia 0.4 +julia 0.5 From a0eda0f066575a486dfc2cdb84f430d71181a2dd Mon Sep 17 00:00:00 2001 From: Kevin Squire Date: Mon, 10 Oct 2016 17:22:57 -0700 Subject: [PATCH 05/10] Various fixes * Rename remaining calls to `err` -> `error` * Fix test function for whether macros are loaded * Internally, call `_configure` instead of `configure` --- README.md | 8 ++++---- src/Logging.jl | 16 +++++++++------- src/logging_macros.jl | 2 +- test/log_test.jl | 16 ++++++++-------- test/macro_test.jl | 24 ++++++++++++------------ test/test_hierarchy.jl | 2 +- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 5ea7ab23..539495f8 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ function log_test() Logging.debug("debug message") Logging.info("info message") Logging.warn("warning message") - Logging.err("error message") + Logging.error("error message") Logging.critical("critical message") end @@ -123,7 +123,7 @@ function macro_log_test() @debug("debug message") @info("info message") @warn("warning message") - @err("error message") + @error("error message") @critical("critical message") end @@ -150,7 +150,7 @@ function macro_log_test() @debug("debug message") @info("info message") @warn("warning message") - @err("error message") + @error("error message") @critical("critical message") end @@ -176,7 +176,7 @@ function macro_log_test() @debug("debug message") @info("info message") @warn("warning message") - @err("error message") + @error("error message") @critical("critical message") end diff --git a/src/Logging.jl b/src/Logging.jl index 15f682fa..3ff5792f 100644 --- a/src/Logging.jl +++ b/src/Logging.jl @@ -74,7 +74,7 @@ Base.show(io::IO, logger::Logger) = print(io, "Logger(", join(Any[logger.name, logger.parent.name], ","), ")") const _root = Logger("root", WARNING, STDERR) -Logger(name::AbstractString;args...) = configure(Logger(name, WARNING, STDERR, _root); args...) +Logger(name::AbstractString;args...) = _configure(Logger(name, WARNING, STDERR, _root); args...) Logger() = Logger("logger") write_log(syslog::SysLog, color::Symbol, msg::AbstractString) = send(syslog.socket, syslog.ip, syslog.port, length(msg) > syslog.maxlength ? msg[1:syslog.maxlength] : msg) @@ -194,10 +194,13 @@ function _logging_funcs_imported() return all(isdefined.([:debug, #=:info, :warn, :error,=# :critical])) end -let _macros_loaded = false - global macros_loaded, set_macros_loaded - macros_loaded() = _macros_loaded - set_macros_loaded() = (_macros_loaded = true) +function _macro_loaded(macroname) + expr = macroexpand(:($(macroname)("hi"))) + return expr.head != :error +end + +function _macros_loaded() + return all(_macro_loaded.([:@debug, :@info, :@warn, :@error, :@critical])) end _src_dir = dirname(@__FILE__) @@ -217,9 +220,8 @@ macro configure(args...) end end - if !Logging.macros_loaded() + if !Logging._macros_loaded() include(joinpath(Logging._src_dir, "logging_macros.jl")) - Logging.set_macros_loaded() end logger end diff --git a/src/logging_macros.jl b/src/logging_macros.jl index 52df3496..49b76985 100644 --- a/src/logging_macros.jl +++ b/src/logging_macros.jl @@ -4,7 +4,7 @@ for (mac,fn,lvl) in ((:debug, :(Logging.debug), Logging.DEBUG), (:info, :(Logging.info), Logging.INFO), (:warn, :(Logging.warn), Logging.WARNING), (:err, :(Logging.err), Logging.ERROR), - (:error, :(Logging.err), Logging.ERROR), + (:error, :(Logging.error), Logging.ERROR), (:critical, :(Logging.critical), Logging.CRITICAL)) @eval macro $mac(msg...) diff --git a/test/log_test.jl b/test/log_test.jl index f277096b..e71f160e 100644 --- a/test/log_test.jl +++ b/test/log_test.jl @@ -2,14 +2,14 @@ using Logging # So that macro tests work # Otherwise, log_test2 uses the default log level of WARNING -@Logging.configure(level=DEBUG) +Logging.@configure(level=DEBUG) function log_test() println("\nTesting function calls:\n") Logging.debug("debug message") Logging.info("info message") Logging.warn("warning message") - Logging.err("error message") + Logging.error("error message") Logging.critical("critical message") end @@ -18,35 +18,35 @@ function log_test2() @debug("debug message") @info("info message") @warn("warning message") - @err("error message") + @error("error message") @critical("critical message") end println("\nSetting level=DEBUG") -Logging.configure(level=DEBUG) +Logging.@configure(level=DEBUG) log_test() log_test2() println() println("\nSetting level=INFO") -Logging.configure(level=INFO) +Logging.@configure(level=INFO) log_test() log_test2() println() println("\nSetting level=WARNING") -Logging.configure(level=WARNING) +Logging.@configure(level=WARNING) log_test() log_test2() println() println("\nSetting level=ERROR") -Logging.configure(level=ERROR) +Logging.@configure(level=ERROR) log_test() log_test2() println() println("\nSetting level=CRITICAL") -Logging.configure(level=CRITICAL) +Logging.@configure(level=CRITICAL) log_test() log_test2() diff --git a/test/macro_test.jl b/test/macro_test.jl index bfbe71b9..58260142 100644 --- a/test/macro_test.jl +++ b/test/macro_test.jl @@ -15,47 +15,47 @@ end module TestDebug using Logging import ..test_log_macro_common -@Logging.configure(level=DEBUG) +Logging.@configure(level=DEBUG) test_log_macro_common([(:@debug, true), (:@info, true), (:@warn, true), - (:@err, true), (:@critical, true)]) + (:@error, true), (:@critical, true)]) end module TestInfo using Logging import ..test_log_macro_common -@Logging.configure(level=INFO) +Logging.@configure(level=INFO) test_log_macro_common([(:@debug, false), (:@info, true), (:@warn, true), - (:@err, true), (:@critical, true)]) + (:@error, true), (:@critical, true)]) end module TestWarning using Logging import ..test_log_macro_common -@Logging.configure(level=WARNING) +Logging.@configure(level=WARNING) test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, true), - (:@err, true), (:@critical, true)]) + (:@error, true), (:@critical, true)]) end module TestError using Logging import ..test_log_macro_common -@Logging.configure(level=ERROR) +Logging.@configure(level=ERROR) test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, false), - (:@err, true), (:@critical, true)]) + (:@error, true), (:@critical, true)]) end module TestCritical using Logging import ..test_log_macro_common -@Logging.configure(level=CRITICAL) +Logging.@configure(level=CRITICAL) test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, false), - (:@err, false), (:@critical, true)]) + (:@error, false), (:@critical, true)]) end module TestOff using Logging import ..test_log_macro_common -@Logging.configure(level=OFF) +Logging.@configure(level=OFF) test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, false), - (:@err, false), (:@critical, false)]) + (:@error, false), (:@critical, false)]) end diff --git a/test/test_hierarchy.jl b/test/test_hierarchy.jl index c2b5f7e3..e60ccaf4 100644 --- a/test/test_hierarchy.jl +++ b/test/test_hierarchy.jl @@ -4,7 +4,7 @@ using Base.Test using Logging # configure root logger -Logging.configure(level=DEBUG) +Logging.@configure(level=DEBUG) root = Logging._root From b37eb27ca53b7a7284d18e7b07b9d5ed2f65bb19 Mon Sep 17 00:00:00 2001 From: Kevin Squire Date: Tue, 11 Oct 2016 21:45:22 -0700 Subject: [PATCH 06/10] Update badges in README --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 539495f8..9d1730d3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,13 @@ -[![Build Status](https://travis-ci.org/kmsquire/Logging.jl.svg?branch=master)](https://travis-ci.org/kmsquire/Logging.jl) -[![Logging](http://pkg.julialang.org/badges/Logging_0.4.svg)](http://pkg.julialang.org/?pkg=Logging) - - Logging.jl: Basic logging for Julia =================================== +[![PkgEval: Julia v0.4](http://pkg.julialang.org/badges/Logging_0.4.svg)](http://pkg.julialang.org/?pkg=Logging) +[![PkgEval: Julia v0.5](http://pkg.julialang.org/badges/Logging_0.5.svg)](http://pkg.julialang.org/?pkg=Logging) +[![PkgEval: Julia v0.6](http://pkg.julialang.org/badges/Logging_0.6.svg)](http://pkg.julialang.org/?pkg=Logging) + +[![TravisCI: Linux, OSX](https://travis-ci.org/kmsquire/Logging.jl.svg?branch=master)](https://travis-ci.org/kmsquire/Logging.jl) +[![AppVeyorCI: Windows](https://ci.appveyor.com/api/projects/status/7cj5kaj8gcxmltho?svg=true)](https://ci.appveyor.com/project/kmsquire/logging-jl) + This module provides basic logging facilities for Julia. It was inspired somewhat by logging in Python. Install with `Pkg.add("Logging")` at the Julia prompt. From b00a42c4443cf0998d6e1576f96ece144312e29c Mon Sep 17 00:00:00 2001 From: Ranjan Anantharaman Date: Tue, 18 Oct 2016 11:16:53 +0530 Subject: [PATCH 07/10] Fix depwarn in test (#52) * Fix `Symbol` depwarn in test * Use `Compat` for v0.4 compatibilty --- test/macro_test.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/macro_test.jl b/test/macro_test.jl index 58260142..f920a9a9 100644 --- a/test/macro_test.jl +++ b/test/macro_test.jl @@ -1,5 +1,6 @@ using Logging using Base.Test +using Compat function test_log_macro_common(flags) for (macroname, isshown) in flags From d508db4064be904bd0cb3319296dce58ddab1fd4 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Thu, 4 May 2017 23:48:39 -0400 Subject: [PATCH 08/10] Attempt to fix Julia v0.6 support (#54) * fix keyword handling in julia v0.6 * use Compat: @static * macro hygiene fixes * ensure that macros work inside modules too --- .travis.yml | 1 + src/Logging.jl | 13 +++++++++- src/logging_macros.jl | 4 ++-- test/macro_scope_test.jl | 51 ++++++++++++++++++++++++++++++++++++++++ test/runtests.jl | 1 + 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 test/macro_scope_test.jl diff --git a/.travis.yml b/.travis.yml index 84a758fb..63a90bd6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ os: - osx julia: - 0.5 + - 0.6 - nightly notifications: email: false diff --git a/src/Logging.jl b/src/Logging.jl index 3ff5792f..8c895cde 100644 --- a/src/Logging.jl +++ b/src/Logging.jl @@ -2,6 +2,8 @@ __precompile__() module Logging +using Compat: @static + export Logger, LogLevel, DEBUG, INFO, WARNING, ERROR, CRITICAL, OFF, LogFacility, @@ -205,9 +207,18 @@ end _src_dir = dirname(@__FILE__) +# Keyword arguments x=1 passed to macros are parsed as Expr(:(=), :x, 1) but +# must be passed as Expr(:(kw), :x, 1) in Julia v0.6. +@static if VERSION < v"0.6-" + fix_kwarg(x) = x +else + fix_kwarg(x::Symbol) = x + fix_kwarg(e::Expr) = e.head == :(=) ? Expr(:(kw), e.args...) : e +end + macro configure(args...) quote - logger = Logging._configure($(args...)) + logger = Logging._configure($([fix_kwarg(a) for a in args]...)) if Logging._imported_with_using() && !Logging._logging_funcs_imported() # We assume that the user has not manually diff --git a/src/logging_macros.jl b/src/logging_macros.jl index 49b76985..ea47513d 100644 --- a/src/logging_macros.jl +++ b/src/logging_macros.jl @@ -15,9 +15,9 @@ for (mac,fn,lvl) in ((:debug, :(Logging.debug), Logging.DEBUG), end if $lvl > level - :nothing + esc(:nothing) else - Expr(:call, $fn, msg...) + Expr(:call, $fn, [esc(m) for m in msg]...) end end diff --git a/test/macro_scope_test.jl b/test/macro_scope_test.jl new file mode 100644 index 00000000..a27d5281 --- /dev/null +++ b/test/macro_scope_test.jl @@ -0,0 +1,51 @@ +# Ensure that Logging.jl works when loaded with `import` rather than `using` +# since `import` does not bring constants like `DEBUG` into scope: +module InnerModule + +import Logging +@Logging.configure(level=DEBUG) + +using Compat +using Base.Test + +function test_non_global_interpolation(y) + @info("y = $y") +end + +test_non_global_interpolation(5) + +function test_log_macro_common(flags) + for (macroname, isshown) in flags + ex = Expr(:macrocall, Symbol(macroname), "test message") + if isshown + @test ex |> macroexpand != :nothing + else + @test ex |> macroexpand == :nothing + end + end +end + +test_log_macro_common([(:@debug, true), (:@info, true), (:@warn, true), + (:@err, true), (:@critical, true)]) + +@Logging.configure(level=INFO) +test_log_macro_common([(:@debug, false), (:@info, true), (:@warn, true), + (:@err, true), (:@critical, true)]) + +@Logging.configure(level=WARNING) +test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, true), + (:@err, true), (:@critical, true)]) + +@Logging.configure(level=ERROR) +test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, false), + (:@err, true), (:@critical, true)]) + +@Logging.configure(level=CRITICAL) +test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, false), + (:@err, false), (:@critical, true)]) + +@Logging.configure(level=OFF) +test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, false), + (:@err, false), (:@critical, false)]) + +end diff --git a/test/runtests.jl b/test/runtests.jl index d9cc0385..cf0f50dd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,3 +1,4 @@ include("log_test.jl") include("macro_test.jl") include("test_hierarchy.jl") +include("macro_scope_test.jl") From 3da6d9e1368a7e31e1713e3e16c179b482b0cd28 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Tue, 16 May 2017 17:16:02 -0700 Subject: [PATCH 09/10] Update CI URLs to point to new caching infrastructure --- appveyor.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index be940168..93974cc2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,9 +1,9 @@ environment: matrix: - - JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe" - - JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" - - JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe" - - JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" + - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" + - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" branches: only: @@ -17,9 +17,10 @@ notifications: on_build_status_changed: false install: + - ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" # Download most recent Julia Windows binary - ps: (new-object net.webclient).DownloadFile( - $("http://s3.amazonaws.com/"+$env:JULIAVERSION), + $env:JULIA_URL, "C:\projects\julia-binary.exe") # Run installer silently, output to C:\projects\julia - C:\projects\julia-binary.exe /S /D=C:\projects\julia From f27cf60dec272f506e0422bcd8d81fd75c93631b Mon Sep 17 00:00:00 2001 From: Kevin Squire Date: Fri, 2 Jun 2017 01:05:54 -0700 Subject: [PATCH 10/10] Remove at-static from Logging.jl * Not needed for functionality, and allows us not to depend on Compat.jl --- src/Logging.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Logging.jl b/src/Logging.jl index 8c895cde..1025732a 100644 --- a/src/Logging.jl +++ b/src/Logging.jl @@ -2,8 +2,6 @@ __precompile__() module Logging -using Compat: @static - export Logger, LogLevel, DEBUG, INFO, WARNING, ERROR, CRITICAL, OFF, LogFacility, @@ -209,7 +207,7 @@ _src_dir = dirname(@__FILE__) # Keyword arguments x=1 passed to macros are parsed as Expr(:(=), :x, 1) but # must be passed as Expr(:(kw), :x, 1) in Julia v0.6. -@static if VERSION < v"0.6-" +if VERSION < v"0.6-" fix_kwarg(x) = x else fix_kwarg(x::Symbol) = x