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/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. diff --git a/REQUIRE b/REQUIRE index 94237c0f..63bcf25a 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1,2 @@ julia 0.5 +Compat 0.7.15 \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..93974cc2 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,35 @@ +environment: + matrix: + - 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: + - master + - /release-.*/ + +notifications: + - provider: Email + on_build_success: false + on_build_failure: false + 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( + $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 + +build_script: +# Need to convert from shallow to complete for Pkg.clone to work + - IF EXIST .git\shallow (git fetch --unshallow) + - C:\projects\julia\bin\julia -e "versioninfo(); + Pkg.clone(pwd(), \"Logging\"); Pkg.build(\"Logging\")" + +test_script: + - C:\projects\julia\bin\julia -e "Pkg.test(\"Logging\")" diff --git a/src/Logging.jl b/src/Logging.jl index 3ff5792f..949993d6 100644 --- a/src/Logging.jl +++ b/src/Logging.jl @@ -2,6 +2,9 @@ __precompile__() module Logging +using Compat: @static +import Base: show + export Logger, LogLevel, DEBUG, INFO, WARNING, ERROR, CRITICAL, OFF, LogFacility, @@ -205,9 +208,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 @@ -220,6 +232,12 @@ macro configure(args...) end end + if Logging.override_info($([fix_kwarg(a) for a in args]...)) + function Base.info(msg::AbstractString...) + Logging.info(Logging._root, msg...) + end + end + if !Logging._macros_loaded() include(joinpath(Logging._src_dir, "logging_macros.jl")) end @@ -228,7 +246,7 @@ macro configure(args...) end function configure(args...; kwargs...) - throw(ErrorException(""" + Base.warn(""" The functional form of Logging.configure(...) is no longer supported. Instead, call 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/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 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")