Skip to content

Commit

Permalink
Use extended brackets instead of box-drawing characters in log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
waldyrious committed Nov 10, 2019
1 parent 6eebbbe commit 7b14980
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 104 deletions.
8 changes: 4 additions & 4 deletions base/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,14 @@ function handle_message(logger::SimpleLogger, level, message, _module, group, id
iob = IOContext(buf, logger.stream)
levelstr = level == Warn ? "Warning" : string(level)
msglines = split(chomp(string(message)), '\n')
println(iob, " ", levelstr, ": ", msglines[1])
println(iob, " ", levelstr, ": ", msglines[1])
for i in 2:length(msglines)
println(iob, " ", msglines[i])
println(iob, " ", msglines[i])
end
for (key, val) in kwargs
println(iob, " ", key, " = ", val)
println(iob, " ", key, " = ", val)
end
println(iob, " @ ", something(_module, "nothing"), " ",
println(iob, " @ ", something(_module, "nothing"), " ",
something(filepath, "nothing"), ":", something(line, "nothing"))
write(logger.stream, take!(buf))
nothing
Expand Down
32 changes: 16 additions & 16 deletions stdlib/Logging/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ statement into the source code, for example:

```julia
@warn "Abandon printf debugging, all ye who enter here!"
Warning: Abandon printf debugging, all ye who enter here!
@ Main REPL[1]:1
Warning: Abandon printf debugging, all ye who enter here!
@ Main REPL[1]:1
```

The system provides several advantages over peppering your source code with
Expand Down Expand Up @@ -36,14 +36,14 @@ v = ones(100)
@info "Some variables" A s=sum(v)
# output
Info: Some variables
A =
4×4 Array{Int64,2}:
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
s = 100.0
Info: Some variables
A =
4×4 Array{Int64,2}:
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
s = 100.0
```

All of the logging macros `@debug`, `@info`, `@warn` and `@error` share common
Expand Down Expand Up @@ -186,11 +186,11 @@ module. For example, loading julia with `JULIA_DEBUG=loading` will activate

```
$ JULIA_DEBUG=loading julia -e 'using OhMyREPL'
Debug: Rejecting cache file /home/user/.julia/compiled/v0.7/OhMyREPL.ji due to it containing an invalid cache header
@ Base loading.jl:1328
Debug: Rejecting cache file /home/user/.julia/compiled/v0.7/OhMyREPL.ji due to it containing an invalid cache header
@ Base loading.jl:1328
[ Info: Recompiling stale cache file /home/user/.julia/compiled/v0.7/OhMyREPL.ji for module OhMyREPL
Debug: Rejecting cache file /home/user/.julia/compiled/v0.7/Tokenize.ji due to it containing an invalid cache header
@ Base loading.jl:1328
Debug: Rejecting cache file /home/user/.julia/compiled/v0.7/Tokenize.ji due to it containing an invalid cache header
@ Base loading.jl:1328
...
```

Expand All @@ -211,8 +211,8 @@ julia> ENV["JULIA_DEBUG"] = Main
Main
julia> foo()
Debug: foo
@ Main REPL[1]:1
Debug: foo
@ Main REPL[1]:1
```

Expand Down
6 changes: 3 additions & 3 deletions stdlib/Logging/src/ConsoleLogger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ function handle_message(logger::ConsoleLogger, level, message, _module, group, i
end
for (i,(indent,msg)) in enumerate(msglines)
boxstr = length(msglines) == 1 ? "[ " :
i == 1 ? " " :
i < length(msglines) ? " " :
" "
i == 1 ? " " :
i < length(msglines) ? " " :
" "
printstyled(iob, boxstr, bold=true, color=color)
if i == 1 && !isempty(prefix)
printstyled(iob, prefix, " ", bold=true, color=color)
Expand Down
138 changes: 69 additions & 69 deletions stdlib/Logging/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,29 @@ end
@test genmsg("line1\nline2", level=Logging.Warn, _module=Base,
file="other.jl", line=42, meta_formatter=Logging.default_metafmt) ==
"""
Warning: line1
line2
@ Base other.jl:42
Warning: line1
line2
@ Base other.jl:42
"""
# Full metadata formatting
@test genmsg("msg", level=Logging.Debug,
meta_formatter=(level, _module, group, id, file, line)->
(:white,"Foo!", "$level $_module $group $id $file $line")) ==
"""
Foo! msg
Debug Main a_group an_id some/path.jl 101
Foo! msg
Debug Main a_group an_id some/path.jl 101
"""

@testset "Prefix and suffix layout" begin
@test genmsg("") ==
replace("""
PREFIX EOL
SUFFIX
PREFIX EOL
SUFFIX
""", "EOL"=>"")
@test genmsg("msg") ==
"""
PREFIX msg
SUFFIX
PREFIX msg
SUFFIX
"""
# Behavior with empty prefix / suffix
@test genmsg("msg", meta_formatter=(args...)->(:white, "PREFIX", "")) ==
Expand All @@ -129,8 +129,8 @@ end
"""
@test genmsg("msg", meta_formatter=(args...)->(:white, "", "SUFFIX")) ==
"""
msg
SUFFIX
msg
SUFFIX
"""
end

Expand All @@ -141,29 +141,29 @@ end
"""
@test genmsg("xxx\nxxx", width=20, right_justify=200) ==
"""
PREFIX xxx
xxx SUFFIX
PREFIX xxx
xxx SUFFIX
"""
# When adding the suffix would overflow the display width, add it on
# the next line:
@test genmsg("xxxx", width=20, right_justify=200) ==
"""
PREFIX xxxx
SUFFIX
PREFIX xxxx
SUFFIX
"""
# Same for multiline messages
@test genmsg("""xxx
xxxxxxxxxx""", width=20, right_justify=200) ==
"""
PREFIX xxx
xxxxxxxxxx SUFFIX
PREFIX xxx
xxxxxxxxxx SUFFIX
"""
@test genmsg("""xxx
xxxxxxxxxxx""", width=20, right_justify=200) ==
"""
PREFIX xxx
xxxxxxxxxxx
SUFFIX
PREFIX xxx
xxxxxxxxxxx
SUFFIX
"""
# min(right_justify,width) is used
@test genmsg("xxx", width=200, right_justify=20) ==
Expand All @@ -172,86 +172,86 @@ end
"""
@test genmsg("xxxx", width=200, right_justify=20) ==
"""
PREFIX xxxx
SUFFIX
PREFIX xxxx
SUFFIX
"""
end

# Keywords
@test genmsg("msg", a=1, b="asdf") ==
"""
PREFIX msg
a = 1
b = "asdf"
SUFFIX
PREFIX msg
a = 1
b = "asdf"
SUFFIX
"""
# Exceptions shown with showerror
@test genmsg("msg", exception=DivideError()) ==
"""
PREFIX msg
exception = DivideError: integer division error
SUFFIX
PREFIX msg
exception = DivideError: integer division error
SUFFIX
"""

# Attaching backtraces
bt = func1()
@test startswith(genmsg("msg", exception=(DivideError(),bt)),
"""
PREFIX msg
exception =
DivideError: integer division error
Stacktrace:
[1] func1() at""")
PREFIX msg
exception =
DivideError: integer division error
Stacktrace:
[1] func1() at""")


@testset "Limiting large data structures" begin
@test genmsg("msg", a=fill(1.00001, 100,100), b=fill(2.00002, 10,10)) ==
replace("""
PREFIX msg
a =
100×100 Array{Float64,2}:
1.00001 1.00001 1.00001 1.00001 … 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
⋮ ⋱ EOL
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
b =
10×10 Array{Float64,2}:
2.00002 2.00002 2.00002 2.00002 … 2.00002 2.00002 2.00002
2.00002 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002
2.00002 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002
⋮ ⋱ EOL
2.00002 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002
2.00002 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002
SUFFIX
PREFIX msg
a =
100×100 Array{Float64,2}:
1.00001 1.00001 1.00001 1.00001 … 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
⋮ ⋱ EOL
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
b =
10×10 Array{Float64,2}:
2.00002 2.00002 2.00002 2.00002 … 2.00002 2.00002 2.00002
2.00002 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002
2.00002 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002
⋮ ⋱ EOL
2.00002 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002
2.00002 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002
SUFFIX
""", "EOL"=>"") # EOL hack to work around git whitespace errors
# Limiting the amount which is printed
@test genmsg("msg", a=fill(1.00001, 10,10), show_limited=false) ==
"""
PREFIX msg
a =
10×10 Array{Float64,2}:
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
SUFFIX
PREFIX msg
a =
10×10 Array{Float64,2}:
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
SUFFIX
"""
end

# Basic colorization test
@test genmsg("line1\nline2", color=true) ==
"""
\e[36m\e[1m \e[22m\e[39m\e[36m\e[1mPREFIX \e[22m\e[39mline1
\e[36m\e[1m \e[22m\e[39mline2
\e[36m\e[1m \e[22m\e[39m\e[90mSUFFIX\e[39m
\e[36m\e[1m \e[22m\e[39m\e[36m\e[1mPREFIX \e[22m\e[39mline1
\e[36m\e[1m \e[22m\e[39mline2
\e[36m\e[1m \e[22m\e[39m\e[90mSUFFIX\e[39m
"""

end
Expand Down
2 changes: 1 addition & 1 deletion test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let exename = `$(Base.julia_cmd()) --startup-file=no`
# make sure this is a non-fatal error and the REPL still loads
@test v[1]
@test isempty(v[2])
@test startswith(v[3], " Warning: Failed to import InteractiveUtils into module Main\n")
@test startswith(v[3], " Warning: Failed to import InteractiveUtils into module Main\n")
end
real_threads = string(ccall(:jl_cpu_threads, Int32, ()))
for nc in ("0", "-2", "x", "2x", " ", "")
Expand Down
22 changes: 11 additions & 11 deletions test/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,32 +327,32 @@ end
# Simple
@test genmsg(Info, "msg", Main, "some/path.jl", 101) ==
"""
Info: msg
@ Main some/path.jl:101
Info: msg
@ Main some/path.jl:101
"""

# Multiline message
@test genmsg(Warn, "line1\nline2", Main, "some/path.jl", 101) ==
"""
Warning: line1
line2
@ Main some/path.jl:101
Warning: line1
line2
@ Main some/path.jl:101
"""

# Keywords
@test genmsg(Error, "msg", Base, "other.jl", 101, a=1, b="asdf") ==
"""
Error: msg
a = 1
b = asdf
@ Base other.jl:101
Error: msg
a = 1
b = asdf
@ Base other.jl:101
"""

# nothing values
@test genmsg(Warn, "msg", nothing, nothing, nothing) ==
"""
Warning: msg
@ nothing nothing:nothing
Warning: msg
@ nothing nothing:nothing
"""
end

Expand Down

0 comments on commit 7b14980

Please sign in to comment.