-
-
Notifications
You must be signed in to change notification settings - Fork 115
Add Compat.at-error, Compat.at-warn, Compat.at-info and Compat.at-debug #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1229,6 +1229,54 @@ end | |
| end | ||
| end | ||
|
|
||
| @static if !isdefined(Base, Symbol("@info")) | ||
| macro info(msg, args...) | ||
| return :(info($(esc(msg)), prefix = "Info: ")) | ||
| end | ||
| else | ||
| @eval const $(Symbol("@info")) = Base.$(Symbol("@info")) | ||
| end | ||
| @static if !isdefined(Base, Symbol("@warn")) | ||
| macro warn(msg, args...) | ||
| return :(warn($(esc(msg)), prefix = "Warning: ")) | ||
| end | ||
| else | ||
| @eval const $(Symbol("@warn")) = Base.$(Symbol("@warn")) | ||
| 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 = 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)))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug messages are invisible by default in 0.7, so I think having them visible here by default might end up being hopelessly verbose. Maybe a simplistic global flag which disables debug by default might be a good idea?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, we can have |
||
| end | ||
| else | ||
| @eval const $(Symbol("@debug")) = Base.$(Symbol("@debug")) | ||
| end | ||
| @static if !isdefined(Base, Symbol("@error")) | ||
| function _error(msg) | ||
| buf = 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 | ||
| else | ||
| @eval const $(Symbol("@error")) = Base.$(Symbol("@error")) | ||
| end | ||
|
|
||
| include("deprecated.jl") | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want 0.6 equivalent formatting, perhaps skip the
prefixfor@infoand@warn?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did it like this to be consistent with 0.7, and also to differentiate logging errors from actual errors, which prints
ERROR:in all caps red.