Crate traccia

Crate traccia 

Source
Expand description

A lightweight, flexible logging framework for Rust applications.

This crate provides a configurable logging system that supports multiple output targets, customizable formatting, and different log levels. It can be used in both synchronous (blocking) and asynchronous contexts.

§Features

  • Multiple log levels (Debug, Info, Warning, Error)
  • Multiple output targets (Console, File)
  • Customizable log formatting
  • Async and blocking implementations

§Example

use logger::{init, LogLevel};

// Initialize with Info level
init(LogLevel::Info);

// Log messages
info!("Application started");
debug!("This won't be displayed with Info level");
error!("Something went wrong: {}", error);

Macros§

debug
Logs a message at the DEBUG level.
error
Logs a message at the ERROR level.
fatal
Logs a message at the FATAL level.
info
Logs a message at the INFO level.
log
Macro for logging messages at a specific level.
span
Creates a new span with the given name and fields.
trace
Logs a message at the TRACE level.
warn
Logs a message at the WARN level.

Structs§

Config
Configuration for initializing a logger.
Console
Standard console output target.
DefaultFormatter
Default log message formatter with configurable span positioning.
DefaultLogger
File
File output target.
FormatterBuilder
Helper builder for creating custom formatters with span positioning support.
Record
Represents a single log record with all relevant metadata.
Span
Represents a single span with a name and key-value pairs.
SpanGuard
A guard that represents an active span.

Enums§

Color
Terminal colors for text output.
Error
FileMode
File open mode for writing log messages.
Hook
Represents a hook that can be set to trigger at specific points in the logging process.
LogLevel
Logging severity levels in ascending order of importance.
Output
Output destination for console log messages.
SpanPosition
Position where span context should appear in log messages.
TargetId
Represents the id of the target where the log message is written. This can be a console output, file path, or a custom string identifier. Useful for identifying the target in hooks / filters.

Traits§

Colorize
Trait for applying colors to strings.
Formatter
Defines a log message formatter.
Logger
Core trait that defines the logging behavior.
Style
Target
Defines an output destination for log messages.

Functions§

current_context
Returns the current span context as a vector of (span_name, key=value) pairs.
enter
Enters a new span with the given name and fields.
format_span_context
Formats span context into a string with default formatting.
format_span_context_with
Formats span context with a custom formatter function.
format_with_span_position
Helper function to format a record with span context at the specified position.
init
Initializes the global logger with the specified minimum log level.
init_default
Initializes the global logger with default settings.
init_with_config
Initializes the global logger with a custom configuration.
logger
Retrieves the global logger instance.
parse_level_from_env
Checks the RUST_LOG env variable and tries to parse its value
set_hook
Sets a hook to be called at the specified point in the logging process.