Debugging: @info display format

I’m trying to get familiar with Logging and am curious about best practices for displaying output. I have a function test which does some operations on a matrix, and I want to see the matrix after some operations.

function test(A::AbstractArray)
    A = A' * A
    @info "A" Diagonal(Matrix(A))
end

From the REPL, I do

julia> A = randn(3,3)
3×3 Array{Float64,2}:
 -1.3463      0.37979    0.116741
  0.448312   -0.778678  -0.276227
  0.0663637  -1.65814    0.306757

julia> @info "diag(A)" Diagonal(Matrix(A))
┌ Info: diag(A)
│   Diagonal(Matrix(A)) =
│    3×3 Diagonal{Float64,Array{Float64,1}}:
│     -1.3463    ⋅         ⋅
│       ⋅      -0.778678   ⋅
└       ⋅        ⋅        0.306757

and the @info message is formatted nicely. However, when I set up a logger and call test, it’s not as nice:

julia> logger=Logging.SimpleLogger(stdout, Logging.Debug)
julia> Logging.with_logger(logger) do; test(A); end
┌ Info: A
│   Diagonal(Matrix(A)) = [2.0179 0.0 0.0; 0.0 3.5 0.0; 0.0 0.0 0.184029]
└ @ Main REPL[30]:3

I tried to display the diagonal, but that didn’t work either. What am I missing about displaying at REPL vs inside a function?

The default logger in the REPL is ConsoleLogger, not SimpleLogger.

2 Likes