https://github.com/ghtaarn/loggingutils.jl
Useful additions to the Logging.jl standard library
https://github.com/ghtaarn/loggingutils.jl
Last synced: 4 months ago
JSON representation
Useful additions to the Logging.jl standard library
- Host: GitHub
- URL: https://github.com/ghtaarn/loggingutils.jl
- Owner: GHTaarn
- License: mit
- Created: 2025-03-26T04:50:52.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-26T20:08:35.000Z (about 1 year ago)
- Last Synced: 2025-11-04T16:09:53.412Z (8 months ago)
- Language: Julia
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LoggingUtils.jl
Some utilies that can be useful in connection with the
[`Logging`](https://docs.julialang.org/en/v1/stdlib/Logging/) standard
library. Also exports all exported symbols from the `Logging` standard
library.
## Installation
From the Julia REPL, execute
```julia
using Pkg
pkg"add https://github.com/GHTaarn/LoggingUtils.jl"
```
or using [FreeRegistry](https://github.com/GHTaarn/FreeRegistry):
```julia
using Pkg
pkg"registry add https://github.com/GHTaarn/FreeRegistry"
pkg"add LoggingUtils"
```
## Use
There are two entry points, `@no_logging` and `@with_logger` which are both
described more precisely in their docstrings.
### Examples
```julia
using LoggingUtils
function verbose_sin(x)
@info "calculating sin"
sin(x)
end
@no_logging println(verbose_sin(8))
mylogger = SimpleLogger()
@with_logger mylogger println(verbose_sin(8))
```
Illustrating that `@no_logging` suppresses logging, whereas `@with_logger`
redirects logging to the specified logger.
### Caveats
Both `@no_logging` and `@with_logger` use the
[`Logging.with_logger`](https://docs.julialang.org/en/v1/stdlib/Logging/#Logging.with_logger)
function internally and therefore assignments must be done externally, e.g.
```julia
using LoggingUtils
function verbose_sin(x)
@info "calculating sin"
sin(x)
end
a = @no_logging verbose_sin(1)
@assert a == sin(1)
@no_logging a = verbose_sin(2)
@assert a == sin(2)
```
where the first assertion would pass and the second would fail.