Disable extra information when using @warn

Hi,
When I use @warn it prints the warning but also where it happened in the script.
Is there a way to disable that information about the line in the script?
Thank you.

idk, but if you only want to print colored fonts, you can use printstyled("warning!!",color=:yellow).

You can use something like LoggingExtras.jl to customise the logging format (you could also use sta functionalities in the Logging stdlib directly, but LoggingExtras.jl provides more user-friendly interface)

using Logging, LoggingExtras

# Logger sink that only prints the level and the message
const message_logger = FormatLogger() do io, args
    println(io, "[", args.level, "] ", args.message)
end

# Filter log messages below info
level_filter_logger = EarlyFilteredLogger(message_logger) do args
    return args.level >= Logging.Info
end

# Install the logger
global_logger(level_filter_logger)
julia> @error "hello error"
[Error] hello error

julia> @warn "hello warn"
[Warn] hello warn

julia> @info "hello info"
[Info] hello info

julia> @debug "hello debug"

4 Likes

Thank you @fredrikekre , I don’t think I would have been able to find that by myself.
If a Base Julia solution exists, I would prefer it as I had bad experience in the past adding dependencies (packages) to my project.

Well you can ofc copy code from the packages or see how they modify the logging but you won’t get this customization any more easily.
What kind of issues did you experience with Julia’s package management? In my experience, it works very well and hickups are quite rare. Maybe there is a misconception we can clear up for you? Or do you require some specialized setup (e.g. air-gapped system) that makes the default not applicable for you?

1 Like

In the past I was using ProgressMeter in my project, one day when I upgraded it, I had a bug that I never manage to fix and I did not raise a issue because I was unable to create a minimum reproducible example. Also the code is behind a corporate firewall so I can’t publish it. I ended up removing ProgressMeter from my project and implemented my own progress bar. All i want to say is that I prefer to have minimal dependencies to my projects cause every dependency has the potential to break it (bug, package not maintained, my inability to understand and fix a bug in a package..etc)
I was not talking about Julia Package manager, but now that you mention it, the only issue I have is that I am behind a proxy and firewall which prevent it from working with the default configuration. To make it work I have to use the option JULIA_PKG_USE_CLI_GIT otherwise it does not work and get an error message saying download is slow. (Sorry i don’t remember the exact error message).

If you don’t mind modifying the call site you can pass _file=nothing _module=nothing _line=nothing like julia/stdlib/REPL/src/REPL.jl at 7e8e9bb12e2ee3f60b5a5c97b15116784958f5d6 · JuliaLang/julia · GitHub

That’s using internals so it may not work forever though.