#progress #logging #log #utilities #java-class

dsi-progress-logger

A Rust port of the ProgressLogger class from the DSI Utilities

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

Download history 173/week @ 2024-09-22 304/week @ 2024-09-29 209/week @ 2024-10-06 149/week @ 2024-10-13 195/week @ 2024-10-20 224/week @ 2024-10-27 481/week @ 2024-11-03 430/week @ 2024-11-10 219/week @ 2024-11-17 212/week @ 2024-11-24 137/week @ 2024-12-01 88/week @ 2024-12-08 99/week @ 2024-12-15 30/week @ 2024-12-22 23/week @ 2024-12-29 138/week @ 2025-01-05

300 downloads per month
Used in 8 crates (4 directly)

Apache-2.0 OR LGPL-2.1-or-later

50KB
806 lines

DSI Progress Logger

downloads dependents GitHub CI license Latest version Documentation

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 macro no_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