Skip to content

Commit c3a1c2b

Browse files
committed
Merge branch 'master' into kms/unexport_functions
2 parents 717f195 + f5c05c4 commit c3a1c2b

File tree

9 files changed

+119
-8
lines changed

9 files changed

+119
-8
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ os:
44
- osx
55
julia:
66
- 0.5
7+
- 0.6
78
- nightly
89
notifications:
910
email: false

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
[![Build Status](https://travis-ci.org/kmsquire/Logging.jl.svg?branch=master)](https://travis-ci.org/kmsquire/Logging.jl)
2-
[![Logging](http://pkg.julialang.org/badges/Logging_0.4.svg)](http://pkg.julialang.org/?pkg=Logging)
3-
4-
51
Logging.jl: Basic logging for Julia
62
===================================
73

4+
[![PkgEval: Julia v0.4](http://pkg.julialang.org/badges/Logging_0.4.svg)](http://pkg.julialang.org/?pkg=Logging)
5+
[![PkgEval: Julia v0.5](http://pkg.julialang.org/badges/Logging_0.5.svg)](http://pkg.julialang.org/?pkg=Logging)
6+
[![PkgEval: Julia v0.6](http://pkg.julialang.org/badges/Logging_0.6.svg)](http://pkg.julialang.org/?pkg=Logging)
7+
8+
[![TravisCI: Linux, OSX](https://travis-ci.org/kmsquire/Logging.jl.svg?branch=master)](https://travis-ci.org/kmsquire/Logging.jl)
9+
[![AppVeyorCI: Windows](https://ci.appveyor.com/api/projects/status/7cj5kaj8gcxmltho?svg=true)](https://ci.appveyor.com/project/kmsquire/logging-jl)
10+
811
This module provides basic logging facilities for Julia. It was inspired somewhat by logging in Python.
912

1013
Install with `Pkg.add("Logging")` at the Julia prompt.

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
julia 0.5
2+
Compat 0.7.15

appveyor.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
environment:
2+
matrix:
3+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
4+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
5+
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
6+
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
7+
8+
branches:
9+
only:
10+
- master
11+
- /release-.*/
12+
13+
notifications:
14+
- provider: Email
15+
on_build_success: false
16+
on_build_failure: false
17+
on_build_status_changed: false
18+
19+
install:
20+
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
21+
# Download most recent Julia Windows binary
22+
- ps: (new-object net.webclient).DownloadFile(
23+
$env:JULIA_URL,
24+
"C:\projects\julia-binary.exe")
25+
# Run installer silently, output to C:\projects\julia
26+
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
27+
28+
build_script:
29+
# Need to convert from shallow to complete for Pkg.clone to work
30+
- IF EXIST .git\shallow (git fetch --unshallow)
31+
- C:\projects\julia\bin\julia -e "versioninfo();
32+
Pkg.clone(pwd(), \"Logging\"); Pkg.build(\"Logging\")"
33+
34+
test_script:
35+
- C:\projects\julia\bin\julia -e "Pkg.test(\"Logging\")"

src/Logging.jl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ __precompile__()
22

33
module Logging
44

5+
using Compat: @static
6+
import Base: show
7+
58
export Logger,
69
LogLevel, DEBUG, INFO, WARNING, ERROR, CRITICAL, OFF,
710
LogFacility,
@@ -205,9 +208,18 @@ end
205208

206209
_src_dir = dirname(@__FILE__)
207210

211+
# Keyword arguments x=1 passed to macros are parsed as Expr(:(=), :x, 1) but
212+
# must be passed as Expr(:(kw), :x, 1) in Julia v0.6.
213+
@static if VERSION < v"0.6-"
214+
fix_kwarg(x) = x
215+
else
216+
fix_kwarg(x::Symbol) = x
217+
fix_kwarg(e::Expr) = e.head == :(=) ? Expr(:(kw), e.args...) : e
218+
end
219+
208220
macro configure(args...)
209221
quote
210-
logger = Logging._configure($(args...))
222+
logger = Logging.configure($([fix_kwarg(a) for a in args]...))
211223

212224
if Logging._imported_with_using() && !Logging._logging_funcs_imported()
213225
# We assume that the user has not manually
@@ -220,6 +232,12 @@ macro configure(args...)
220232
end
221233
end
222234

235+
if Logging.override_info($([fix_kwarg(a) for a in args]...))
236+
function Base.info(msg::AbstractString...)
237+
Logging.info(Logging._root, msg...)
238+
end
239+
end
240+
223241
if !Logging._macros_loaded()
224242
include(joinpath(Logging._src_dir, "logging_macros.jl"))
225243
end
@@ -228,7 +246,7 @@ macro configure(args...)
228246
end
229247

230248
function configure(args...; kwargs...)
231-
throw(ErrorException("""
249+
Base.warn("""
232250
The functional form of Logging.configure(...) is no longer supported.
233251
Instead, call
234252

src/logging_macros.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ for (mac,fn,lvl) in ((:debug, :(Logging.debug), Logging.DEBUG),
1515
end
1616

1717
if $lvl > level
18-
:nothing
18+
esc(:nothing)
1919
else
20-
Expr(:call, $fn, msg...)
20+
Expr(:call, $fn, [esc(m) for m in msg]...)
2121
end
2222
end
2323

test/macro_scope_test.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Ensure that Logging.jl works when loaded with `import` rather than `using`
2+
# since `import` does not bring constants like `DEBUG` into scope:
3+
module InnerModule
4+
5+
import Logging
6+
@Logging.configure(level=DEBUG)
7+
8+
using Compat
9+
using Base.Test
10+
11+
function test_non_global_interpolation(y)
12+
@info("y = $y")
13+
end
14+
15+
test_non_global_interpolation(5)
16+
17+
function test_log_macro_common(flags)
18+
for (macroname, isshown) in flags
19+
ex = Expr(:macrocall, Symbol(macroname), "test message")
20+
if isshown
21+
@test ex |> macroexpand != :nothing
22+
else
23+
@test ex |> macroexpand == :nothing
24+
end
25+
end
26+
end
27+
28+
test_log_macro_common([(:@debug, true), (:@info, true), (:@warn, true),
29+
(:@err, true), (:@critical, true)])
30+
31+
@Logging.configure(level=INFO)
32+
test_log_macro_common([(:@debug, false), (:@info, true), (:@warn, true),
33+
(:@err, true), (:@critical, true)])
34+
35+
@Logging.configure(level=WARNING)
36+
test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, true),
37+
(:@err, true), (:@critical, true)])
38+
39+
@Logging.configure(level=ERROR)
40+
test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, false),
41+
(:@err, true), (:@critical, true)])
42+
43+
@Logging.configure(level=CRITICAL)
44+
test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, false),
45+
(:@err, false), (:@critical, true)])
46+
47+
@Logging.configure(level=OFF)
48+
test_log_macro_common([(:@debug, false), (:@info, false), (:@warn, false),
49+
(:@err, false), (:@critical, false)])
50+
51+
end

test/macro_test.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Logging
22
using Base.Test
3+
using Compat
34

45
function test_log_macro_common(flags)
56
for (macroname, isshown) in flags

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include("log_test.jl")
22
include("macro_test.jl")
33
include("test_hierarchy.jl")
4+
include("macro_scope_test.jl")

0 commit comments

Comments
 (0)