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

dsi-progress-logger

A tunable time-based progress logger to log progress information about long-running activities

18 releases (7 breaking)

new 0.8.0 Feb 20, 2025
0.6.0 Feb 4, 2025
0.2.5 Nov 6, 2024
0.2.4 Mar 25, 2024
0.1.3 Jun 13, 2023

#118 in Debugging

Download history 164/week @ 2024-10-30 541/week @ 2024-11-06 361/week @ 2024-11-13 260/week @ 2024-11-20 171/week @ 2024-11-27 109/week @ 2024-12-04 94/week @ 2024-12-11 62/week @ 2024-12-18 19/week @ 2024-12-25 37/week @ 2025-01-01 217/week @ 2025-01-08 69/week @ 2025-01-15 132/week @ 2025-01-22 487/week @ 2025-01-29 274/week @ 2025-02-05 312/week @ 2025-02-12

1,213 downloads per month
Used in 8 crates (4 directly)

Apache-2.0 OR LGPL-2.1-or-later

60KB
950 lines

DSI Progress Logger

downloads dependents GitHub CI license Latest version Documentation

A tunable time-based 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, with new features such as concurrent updates. Logging is based on the standard log crate at the info level.

There is a ProgressLog trait and a default implementation ProgressLogger.

Concurrent Logging

If you need to log progress from multiple threads, you can use a ConcurrentProgressLog, which is obtained, for example, by wrapping a ProgressLog implementation using a ConcurrentWrapper.

ConcurrentProgressLog extends ProgressLog, but when you clone a ConcurrentProgressLog you obtain a new ConcurrentProgressLog, based on the same underlying ProgressLog, that can be passed to other threads. As a result, a ConcurrentProgressLog can be used with methods like rayon::ParallelIterator::for_each_with, rayon::ParallelIterator::map_with, and so on. 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! 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.

All of the above applies to ConcurrentProgressLog, too. Moreover, the ProgressLog::concurrent method can be used to obtain a ConcurrentProgressLog from a ProgressLog. Thus, in case you need both sequential and concurrent logging you can pass a &mut impl ProgressLog and then obtain a concurrent logger from it. If the original logger is None, the concurrent logger will be None, too, and so on.

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.

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
~85K SLoC