@@ -93,6 +93,7 @@ All of them, except `FormatLogger`, just wrap existing loggers.
9393 - The ` FileLogger ` is a simple logger sink that writes to file.
9494 - The ` DatetimeRotatingFileLogger ` is a logger sink that writes to file, rotating logs based upon a user-provided ` DateFormat ` .
9595 - The ` FormatLogger ` is a logger sink that simply formats the message and writes to the logger stream.
96+ - The ` LevelOverrideLogger ` for overriding the log level of other loggers
9697
9798By combining ` TeeLogger ` with filter loggers you can arbitrarily route log messages, wherever you want.
9899
@@ -364,6 +365,56 @@ Main | [Info] This is an informational message.
364365Main | [Warn] This is a warning, should take a look.
365366```
366367
368+ ## `LevelOverrideLogger` (*Filter*)
369+ Allows overriding the log level set by any nested logger. Useful when debug logging
370+ and used in conjuction with `Logging.with_logger` or `LoggingExtras.with` to
371+ temporarily modify the current logger with a custom level.
372+
373+ ``` julia
374+ julia> using LoggingExtras
375+
376+ julia> logger = LevelOverrideLogger (Debug, global_logger ())
377+
378+ julia> with_logger (logger) do
379+ @debug " This message will log since we're overriding the global Info default log level"
380+ end
381+ ┌ Debug: This message will log since we' re overriding the global Info default log level
382+ └ @ Main REPL[33 ]: 2
383+ ```
384+
385+ # Utilities
386+
387+ ## Verbosity macros
388+ Sometimes when logging, it is desirable to be able to specify a verbosity level in addition to
389+ the log level, and to be able to filter on verbosity levels. For example, you may want multiple levels
390+ of verbosity for `Debug` log statements. LoggingExtras.jl exports verbosity macros that act like their
391+ non-verbose counterparts, but allow specifying a verbosity level as well:
392+ * `@debugv N msg`
393+ * `@infov N msg`
394+ * `@warnv N msg`
395+ * `@errorv N msg`
396+
397+ For verbosity filtering, the `LoggingExtras.with(f; level=Info, verbosity=0)` utlility is provided
398+ for temporarily (i.e. while `f()` is executed) allowing log messages with `level` and `verbosity`.
399+ This is very handy for allowing control in debug logging for long-running or complex user API function
400+ calls. For example:
401+
402+ ``` julia
403+ using LoggingExtras
404+
405+ function complex_user_call (; verbose= 0 )
406+ LoggingExtras. with (; level= Debug, verbosity= verbose)
407+ # execute complex function body
408+ @debugv 1 " a level 1 verbosity debug message"
409+ @debugv 2 " a more verbose level 2 debug message"
410+ end
411+ end
412+ ```
413+
414+ This allows easy control by the user to specify verbosity (by passing `verbose=2` or any > 0 value),
415+ and convenience for the function developer by being able to sprinkle `@debugv N msg` calls as desired,
416+ even in highly nested functions.
417+
367418# More Examples
368419
369420## Filter out any overly long messages
0 commit comments