A flexible verbosity control system for the SciML ecosystem that allows fine-grained control over logging, warnings.
Installation
using Pkg
Pkg.add("SciMLLogging")
SciMLLogging.jl provides a structured approach to controlling verbosity in scientific computing workflows. It enables:
Fine-grained control over which messages are displayed and at what levels Hierarchical organization of verbosity settings by component and message type
Consistent logging patterns across the SciML ecosystem
using SciMLLogging
using Logging
# Create a simple verbosity structure
struct MyVerbosity{T} <: AbstractVerbositySpecifier{T}
algorithm_choice::Verbosity.LogLevel
iteration_progress::Verbosity.LogLevel
function MyVerbosity{T}(;
algorithm_choice = Verbosity.Warn(),
iteration_progress = Verbosity.Info()
) where {T}
new{T}(algorithm_choice, iteration_progress)
end
end
# Create enabled verbosity
verbose = MyVerbosity{true}()
# Log messages at different levels
@SciMLMessage("Selected algorithm: GMRES", verbose, :algorithm_choice)
@SciMLMessage("Iteration 5/100 complete", verbose, :iteration_progress)
# Use a function to create the message
@SciMLMessage(verbose, :iteration_progress) do
iter = 10
total = 100
progress = iter/total * 100
"Iteration $iter/$total complete ($(round(progress, digits=1))%)"
end
SciMLLogging supports several verbosity levels:
Verbosity.Silent()
: No outputVerbosity.Info()
: Informational messagesVerbosity.Warn()
: Warning messagesVerbosity.Error()
: Error messagesVerbosity.Level(n)
: Custom logging level (using Julia's LogLevel(n))
- Define a structure for each group of verbosity options
- Create a main verbosity struct that inherits from AbstractVerbositySpecifier{T}
- Define constructors for easy creation and default values Example:
# Main verbosity struct with direct LogLevel fields
struct MyAppVerbosity{T} <: AbstractVerbositySpecifier{T}
solver_iterations::Verbosity.LogLevel
solver_convergence::Verbosity.LogLevel
performance_timing::Verbosity.LogLevel
performance_memory::Verbosity.LogLevel
function MyAppVerbosity{T}(;
solver_iterations = Verbosity.Info(),
solver_convergence = Verbosity.Warn(),
performance_timing = Verbosity.Silent(),
performance_memory = Verbosity.Silent()
) where {T}
new{T}(solver_iterations, solver_convergence, performance_timing, performance_memory)
end
end
# Constructor with enable/disable parameter
MyAppVerbosity(; enable = true, kwargs...) = MyAppVerbosity{enable}(; kwargs...)
Integration with Julia's Logging System SciMLVerbosity integrates with Julia's built-in logging system. You can customize how logs are handled with the SciMLLogger, which allows you to direct logs to different outputs. Or you can use your own logger based on the Julia logging system or LoggingExtras.jl.
# Create a logger that sends warnings to a file
log_file = "warnings.log"
logger = SciMLLogger(
info_repl = true, # Show info in REPL
warn_repl = true, # Show warnings in REPL
error_repl = true, # Show errors in REPL
warn_file = log_file # Also log warnings to file
)
# Use the logger
with_logger(logger) do
# Your code with @SciMLMessage calls
end
Disabling Verbosity To completely disable verbosity without changing your code:
# Create disabled verbosity
silent = MyVerbosity{false}()
# This won't produce any output
@SciMLMessage("This message won't be shown", silent, :algorithm_choice)
SciMLLogging.jl is licensed under the MIT License.