https://github.com/tpapp/hdf5logging.jl
Log to HDF5 files from Julia.
https://github.com/tpapp/hdf5logging.jl
Last synced: 4 months ago
JSON representation
Log to HDF5 files from Julia.
- Host: GitHub
- URL: https://github.com/tpapp/hdf5logging.jl
- Owner: tpapp
- License: other
- Created: 2021-04-13T13:43:53.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-13T13:50:36.000Z (about 5 years ago)
- Last Synced: 2026-01-20T20:04:53.222Z (5 months ago)
- Language: Julia
- Size: 8.79 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# HDF5Logging.jl
 [](https://github.com/tpapp/HDF5Logging.jl/actions?query=workflow%3ACI) [](http://codecov.io/github/tpapp/HDF5Logging.jl?branch=master)
**`HDF5Logging.hdf5_logger`** — *Function*.
```julia
hdf5_logger(filename; group_path)
```
Create a logger that write log messages into the HDF5 file `filename` within the given `group_path` (defaults to `"log"`).
**Logging**
A counter keeps track of an increasing integer index. A log message is written to the given `group_path` as a group named with this index (converted to a string), with the following fields:
* `level::Int`, `message::String`, `_module::String`, `group::String`, `id::String`, `file::String`, `line::String`, which are part of every log message
* `data`, which contains additional key-value pairs as passed on by the user. Keys are strings.
**Reading logs**
`length(logger)` returns the last index of logged messages, which can be be accessed with `logger[i]`. The latter returns a `NamedTuple`, or `nothing` for no such message.
**Example**
```julia-repl
julia> using HDF5Logging, Logging
julia> logger = hdf5_logger(tempname())
Logging into HDF5 file /tmp/jl_IbbUvj, 0 messages in “log”
julia> # write log
julia> with_logger(logger) do
@info "very informative" a = 1
end
julia> # read log
julia> logger[1]
(level = Info, message = "very informative", _module = "Main", group = "REPL[46]", id = "Main_7a40b9cc", file = "REPL[46]", line = 2, data = ["a" => 1])
```
**Notes**
1. The HDF5 file can contain other data, ideally in other groups than `group_path`.
2. Contiguity of message indexes is not checked. This package will create them in order,
starting at 1, but if you delete some with another tool then `getindex` will just return `nothing`.
3. A lock is used, so a shared instance should be thread-safe. That said, **if you open the
same file with another `hdf5_logger`, consequences are undefined.**
4. The HDF5 file is not kept open when not accessed. This is slower, but should help ensure
robust operation.