Skip to content

Commit

Permalink
Drop compat code for at-warn and friends from #458
Browse files Browse the repository at this point in the history
And mark `enable_debug(::Bool)` for deprecation.
  • Loading branch information
martinholters committed Oct 8, 2019
1 parent 8b77d31 commit 833a0b0
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 76 deletions.
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,6 @@ Currently, the `@compat` macro supports the following syntaxes:

## New macros

* The logging macros `@error`, `@warn`, `@info` and `@debug` can be used as
`Compat.@error`, `Compat.@warn`, `Compat.@info` and `Compat.@debug` on Julia 0.6 ([#24490]).
Note that the behavior do not mirror the logging macros in Julia 0.7, instead on Julia 0.6:
- Messages are printed to `STDERR` (like `info` and `warn` on Julia 0.6) and not to a
dedicated logging stream.
- The loglevel can not be controlled, but `Compat.@debug` messages can be turned on/off
by calling `Compat.enable_debug(true/false)`.
- Extra metadata sent to the macros are ignored.

As an alternative, see the MicroLogging.jl package for a logging interface similar to the one in Julia 0.7.

## Other changes

* On versions of Julia that do not contain a Base.Threads module, Compat defines a Threads module containing a no-op `@threads` macro.
Expand Down
42 changes: 1 addition & 41 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ end
import Base: notnothing
const IteratorSize = Base.IteratorSize
const IteratorEltype = Base.IteratorEltype
enable_debug(x::Bool) = x


include("compatmacro.jl")
Expand All @@ -70,47 +71,6 @@ end
end
end

@static if !isdefined(Base, Symbol("@info"))
macro info(msg, args...)
return :(info($(esc(msg)), prefix = "Info: "))
end
end
@static if !isdefined(Base, Symbol("@warn"))
macro warn(msg, args...)
return :(warn($(esc(msg)), prefix = "Warning: "))
end
end

const DEBUG = Ref(false) # debug printing off by default, as on 0.7
enable_debug(x::Bool) = DEBUG[] = x
@static if !isdefined(Base, Symbol("@debug"))
function debug(msg)
DEBUG[] || return
buf = Base.IOBuffer()
iob = Base.redirect(IOContext(buf, STDERR), Base.log_info_to, :debug)
print_with_color(:blue, iob, "Debug: "; bold = true)
Base.println_with_color(:blue, iob, chomp(string(msg)))
print(STDERR, String(take!(buf)))
return
end
macro debug(msg, args...)
return :(debug($(esc(msg))))
end
end
@static if !isdefined(Base, Symbol("@error"))
function _error(msg)
buf = Base.IOBuffer()
iob = Base.redirect(IOContext(buf, STDERR), Base.log_error_to, :error)
print_with_color(Base.error_color(), iob, "Error: "; bold = true)
Base.println_with_color(Base.error_color(), iob, chomp(string(msg)))
print(STDERR, String(take!(buf)))
return
end
macro error(msg, args...)
return :(_error($(esc(msg))))
end
end

# 0.7.0-DEV.3415
if !isdefined(Base, :findall)
const findall = find
Expand Down
24 changes: 0 additions & 24 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,6 @@ let A = [1]
@test x == 1
end

if !isdefined(Base, Symbol("@info"))
let fname = tempname()
try
open(fname, "w") do fout
redirect_stderr(fout) do
Compat.@info "A"
Compat.@warn "B"
oldstate = Compat.DEBUG[]
Compat.enable_debug(false)
Compat.@debug "C"
Compat.enable_debug(true)
Compat.@debug "D"
Compat.enable_debug(oldstate)
Compat.@error "E"
end
end
@test read(fname, String) == (Base.have_color ? "\e[1m\e[36mInfo: \e[39m\e[22m\e[36mA\n\e[39m\e[1m\e[33mWarning: \e[39m\e[22m\e[33mB\e[39m\n\e[1m\e[34mDebug: \e[39m\e[22m\e[34mD\n\e[39m\e[1m\e[91mError: \e[39m\e[22m\e[91mE\n\e[39m" :
"Info: A\nWarning: B\nDebug: D\nError: E\n")
finally
rm(fname, force=true)
end
end
end

# 0.7.0-DEV.3460
@test parentmodule(Compat.Sys) == Compat
@test parentmodule(sin) == Base
Expand Down

0 comments on commit 833a0b0

Please sign in to comment.