Skip to content

Commit

Permalink
Merge branch 'master' into kms/unexport_functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kmsquire committed May 28, 2017
2 parents 717f195 + f5c05c4 commit c3a1c2b
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ os:
- osx
julia:
- 0.5
- 0.6
- nightly
notifications:
email: false
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.5
Compat 0.7.15
35 changes: 35 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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\")"
22 changes: 20 additions & 2 deletions src/Logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ __precompile__()

module Logging

using Compat: @static
import Base: show

export Logger,
LogLevel, DEBUG, INFO, WARNING, ERROR, CRITICAL, OFF,
LogFacility,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/logging_macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
51 changes: 51 additions & 0 deletions test/macro_scope_test.jl
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/macro_test.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Logging
using Base.Test
using Compat

function test_log_macro_common(flags)
for (macroname, isshown) in flags
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include("log_test.jl")
include("macro_test.jl")
include("test_hierarchy.jl")
include("macro_scope_test.jl")

0 comments on commit c3a1c2b

Please sign in to comment.