lenskit.logging#
Logging, progress, and resource records.
Submodules#
Multiprocess logging support for Ray integration. Most code doesn't need to |
|
Abstraction for recording tasks. |
Attributes#
Classes#
Configuration for LensKit logging. |
|
Single measurement of resources. Two measurements can be subtracted to |
|
Timer class for recording elapsed wall time in operations. |
|
Logger-like thing that is only for TRACE-level events. |
Functions#
|
Simple one-function logging configuration for simple command lines. |
|
Simple one-function logging configuration for notebooks and similar. |
Get a console attached to |
|
|
Short, human-friendly representation of a duration. |
|
Get a logger. This works like |
|
Get a tracer for efficient low-level tracing of computations. |
|
Emit a trace-level message, if LensKit tracing is enabled. Trace-level |
Package Contents#
- class lenskit.logging.LoggingConfig#
Configuration for LensKit logging.
This class is intended as a convenience for LensKit applications to set up a useful logging and progress reporting configuration; if unconfigured, LensKit will emit its logging messages directly to
structlogand/orlogging, which you can configure in any way you wish.- Stability:
- Caller (see Stability Levels).
- stream: Literal['full', 'simple', 'json'] = 'full'#
- file: pathlib.Path | None = None#
- file_format: LogFormat = 'json'#
- set_stream_mode(mode)#
Configure the standard error stream mode.
- Parameters:
mode (Literal['full', 'simple', 'json'])
- set_verbose(verbose=True)#
Enable verbose logging.
Note
It is better to only call this method if your application’s
verboseoption is provided, rather than passing your verbose option to it, to allow theLK_LOG_LEVELenvironment variable to apply in the absence of a configuration option.
- set_log_file(path, level=None, format='json')#
Configure a log file.
- Parameters:
path (os.PathLike[str])
level (int | None)
format (LogFormat)
- apply()#
Apply the configuration.
- lenskit.logging.basic_logging(level=logging.INFO)#
Simple one-function logging configuration for simple command lines.
- Stability:
- Caller (see Stability Levels).
- Parameters:
level (int)
- lenskit.logging.notebook_logging(level=logging.INFO)#
Simple one-function logging configuration for notebooks and similar.
- Stability:
- Caller (see Stability Levels).
- Parameters:
level (int)
- lenskit.logging.console#
- lenskit.logging.stdout_console()#
Get a console attached to
stdout.
- lenskit.logging.friendly_duration(elapsed)#
Short, human-friendly representation of a duration.
- Parameters:
elapsed (float | datetime.timedelta)
- lenskit.logging.get_logger(name, *, remove_private=True, **init_als)#
Get a logger. This works like
structlog.stdlib.get_logger(), except the returned proxy logger is quiet (only WARN and higher messages) if structlog has not been configured. LensKit code should use this instead of obtaining loggers from Structlog directly.It also suppresses private module name components of the logger name, so e.g.
lenskit.pipeline._implbecomes ``lenskit.pipeline`.- Params:
- name:
The logger name.
- remove_private:
Set to
Falseto keep private module components of the logger name instead of removing them.- init_vals:
Initial values to bind into the logger when crated.
- Returns:
A lazy proxy logger. The returned logger is type-compatible with
structlib.stdlib.BoundLogger, but is actually an instance of an internal proxy that provies more sensible defaults and handles LensKit’s TRACE-level logging support.- Parameters:
- Return type:
- class lenskit.logging.ResourceMeasurement#
Single measurement of resources. Two measurements can be subtracted to compute the time resources consumed in an interval (memory resources are left unchanged).
- Stability:
- Internal (see Stability Levels).
- classmethod current()#
Get the current resource measurements.
- __sub__(other)#
- Parameters:
other (ResourceMeasurement)
- class lenskit.logging.Stopwatch(start=True)#
Timer class for recording elapsed wall time in operations.
- start()#
- stop()#
- measure(accumulate=False)#
Context manager to measure an item, optionally accumulating its time.
- Parameters:
accumulate (bool)
- __str__()#
- __repr__()#
- class lenskit.logging.Tracer(logger)#
Logger-like thing that is only for TRACE-level events.
This class is designed to support structured tracing without the overhead of creating and binding new loggers. It is also imperative, rather than functional, so we create fewer objects and so it is a little more ergonomic for common tracing flows.
Note
Don’t create instances of this class directly — use
get_tracer()to create a tracer.- Stability:
Experimental
- Parameters:
logger (structlog.stdlib.BoundLogger)
- add_bindings(**new_values)#
Bind new data in the keys.
Note
Unlike
structlog.Logger.bind(), this method is **imperative*: it updates the tracer in-place instead of returning a new tracer. If you need a new, disconnected tracer, usesplit().- Parameters:
new_values (Any)
- Return type:
None
- remove_bindings(*keys)#
Unbind keys in the tracer.
Note
Unlike
structlog.Logger.bind(), this method is **imperative*: it updates the tracer in-place instead of returning a new tracer. If you need a new, disconnected tracer, usesplit().- Parameters:
keys (str)
- Return type:
None
- reset()#
Reset this tracer’s underlying logger to the original logger.
- Return type:
None
- lenskit.logging.get_tracer(logger, **initial_values)#
Get a tracer for efficient low-level tracing of computations.
- Stability:
Experimental
- Parameters:
logger (str | structlog.stdlib.BoundLogger)
initial_values (Any)
- lenskit.logging.trace(logger, *args, **kwargs)#
Emit a trace-level message, if LensKit tracing is enabled. Trace-level messages are more fine-grained than debug-level messages, and you usually don’t want them.
This function does not work on the lazy proxies returned by
get_logger()and similar — it only works on bound loggers.- Stability:
- Caller (see Stability Levels).
- Parameters:
logger (structlog.stdlib.BoundLogger)
args (Any)
kwargs (Any)
Exported Aliases#
- class lenskit.logging.Progress#
Re-exported alias for
lenskit.logging.progress.Progress.
- lenskit.logging.item_progress()#
Re-exported alias for
lenskit.logging.progress.item_progress().
- lenskit.logging.set_progress_impl()#
Re-exported alias for
lenskit.logging.progress.set_progress_impl().
- class lenskit.logging.Task#
Re-exported alias for
lenskit.logging.tasks.Task.