Skip to main content

setup_logging

Function setup_logging 

Source
pub fn setup_logging(config: LoggingConfig) -> Result<LogSetupReturn>
Expand description

Sets up a fully filtered tracing logging system with a global env filter applied at the registry level. This ensures all layers (stdout, file, etc.) only receive events that pass the global filter.

By default with the minimal config a stdout layer is setup with a custom env filter that filters according to the specified log level, as well as according to a list of hardcoded crates. See build_env_filter for hardcoded crate log filtering. Optionally, file logging can be configured with FileLoggingConfig, which minimally will create a timestamp prefixed log file in the given path that does not rotate (one log file per program execution)

Extra configuration for file logging is:

  • Log file rotation. See LogRotation for possible options

Returns LogSetupReturn, which is a composite struct containing objects that need to be retained by the client such as:

  • LogReloadHandle, for setting a new global log level during runtime
  • WorkerGuard, so that the non-blocking file writer can continue writing. This cannot be dropped and needs to be kept alive for the duration of the program execution
  • [ErrorAggregationContainer], if the [error_aggregation] feature is enabled. This object allows recent errors to be queried from the logging framework