12 releases
new 0.3.0 | Jan 10, 2025 |
---|---|
0.2.5 | Nov 6, 2024 |
0.2.4 | Mar 25, 2024 |
0.2.2 | Nov 2, 2023 |
0.1.1 | May 21, 2023 |
#183 in Debugging
300 downloads per month
Used in 8 crates
(4 directly)
50KB
806 lines
DSI Progress Logger
A tunable progress logger to log progress information about long-running activities.
It is a port of the Java class it.unimi.dsi.util.ProgressLogger
from the
DSI Utilities. Logging is based on the standard log
crate at the info
level.
There is a ProgressLog
trait and a default implementation
ProgressLogger
.
Concurrent Logging
A ProgressLogger
is not thread-safe. If you need to log from multiple
threads, you can use ConcurrentWrapper
to wrap a ProgressLog
implementation. ConcurrentWrapper
implements ProgressLog
, but it
features also an additional method spawn
that returns a new thread-safe
ConcurrentWrapper
with the same underlying ProgressLog
implementation
that can be passed to other threads. Convenience constructors and macros make
concurrent progress logging as easy as single-threaded logging.
Optional Logging
This crate supports optional logging by implementing ProgressLog
for
Option<ProgressLog>::None
as a no-op. As a result, you can pass to functions
an argument pl
that is a &mut impl ProgressLog
, with the following behavior:
- if you pass a
&mut ProgressLogger
, the progress logger will be used, without any check; - if you pass a
&mut Option::<ProgressLogger>::None
, no logging will be performed, and in fact the logging code should be entirely optimized away by the compiler; the macrono_logging!
, which expands to&mut Option::<ProgressLogger>::None
, can be used a convenient way to switch off logging; - if you pass an
&mut Option<ProgressLogger>
, logging will happen depending on the variant, and there will be a runtime check for each call.
There is an info
method that can be used to log information to the logger at
the info
level. The advantage of using info
is that the logging will be
optional depending on the type of the logger.
Cloning
The clone
method will return a logger with the same setup but with all the
counters reset. This is useful when you want to configure a logger and then use
its configuration for other loggers.
Acknowledgments
This software has been partially supported by project SERICS (PE00000014) under the NRRP MUR program funded by the EU - NGEU. Views and opinions expressed are however those of the authors only and do not necessarily reflect those of the European Union or the Italian MUR. Neither the European Union nor the Italian MUR can be held responsible for them.
Dependencies
~3.5–4.5MB
~88K SLoC