Classes
LogLevel
Log levels in order of severity.
LogLevel
Log levels in order of severity.
Enum
LogEvent
dataclass
Structured log event with context.
LogEvent
dataclass Structured log event with context.
Attributes
| Name | Type | Description |
|---|---|---|
timestamp |
str |
|
level |
str |
|
logger_name |
str |
|
event_type |
str |
|
message |
str |
|
phase |
str | None |
|
phase_depth |
int |
|
duration_ms |
float | None |
|
memory_mb |
float | None |
|
peak_memory_mb |
float | None |
|
context |
dict[str, Any] |
Methods 2
to_dict
Convert to dictionary for JSON serialization.
to_dict
def to_dict(self) -> dict[str, Any]
Convert to dictionary for JSON serialization.
Returns
dict[str, Any]
format_console
Format for console output using Rich markup.
format_console
def format_console(self, verbose: bool = False) -> str
Format for console output using Rich markup.
Parameters 1
verbose |
bool |
Returns
str
BengalLogger
Phase-aware structured logger for Bengal builds.
Tracks build phases, emits structured events, and…
BengalLogger
Phase-aware structured logger for Bengal builds.
Tracks build phases, emits structured events, and provides timing information. All logs are written to both console and a build log file.
Methods 10
phase
Context manager for tracking build phases with timing and memory.
phase
def phase(self, name: str, **context: Any) -> Any
Context manager for tracking build phases with timing and memory.
Parameters 1
name |
str |
Phase name **context: Additional context to attach to all events in phase |
Returns
Any
debug
Log debug event.
debug
def debug(self, message: str, **context: Any) -> None
Log debug event.
Parameters 1
message |
str |
info
Log info event.
info
def info(self, message: str, **context: Any) -> None
Log info event.
Parameters 1
message |
str |
warning
Log warning event.
warning
def warning(self, message: str, **context: Any) -> None
Log warning event.
Parameters 1
message |
str |
error
Log error event.
error
def error(self, message: str, **context: Any) -> None
Log error event.
Parameters 1
message |
str |
critical
Log critical event.
critical
def critical(self, message: str, **context: Any) -> None
Log critical event.
Parameters 1
message |
str |
get_events
Get all logged events.
get_events
def get_events(self) -> list[LogEvent]
Get all logged events.
Returns
list[LogEvent]
get_phase_timings
Extract phase timings from events.
get_phase_timings
def get_phase_timings(self) -> dict[str, float]
Extract phase timings from events.
Returns
Dict mapping phase names to duration in millisecondsdict[str, float]
—
print_summary
Print timing summary of all phases.
print_summary
def print_summary(self) -> None
Print timing summary of all phases.
close
Close log file handle.
close
def close(self) -> None
Close log file handle.
Internal Methods 4
__init__
Initialize logger.
__init__
def __init__(self, name: str, level: LogLevel = LogLevel.INFO, log_file: Path | None = None, verbose: bool = False, quiet_console: bool = False)
Initialize logger.
Parameters 5
name |
str |
Logger name (typically name) |
level |
LogLevel |
Minimum log level to emit |
log_file |
Path | None |
Path to log file (optional) |
verbose |
bool |
Whether to show verbose output |
quiet_console |
bool |
Suppress console output (for live progress mode) |
_emit
Emit a log event.
_emit
def _emit(self, level: LogLevel, message: str, **context: Any) -> None
Emit a log event.
Parameters 2
level |
LogLevel |
Log level |
message |
str |
Human-readable message **context: Additional context data |
__enter__
Context manager entry.
__enter__
def __enter__(self) -> BengalLogger
Context manager entry.
Returns
BengalLogger
__exit__
Context manager exit.
__exit__
def __exit__(self, exc_type: type[BaseException] | None, *args: Any) -> None
Context manager exit.
Parameters 1
exc_type |
type[BaseException] | None |
_GlobalConfig
_GlobalConfig
TypedDictAttributes
| Name | Type | Description |
|---|---|---|
level |
LogLevel |
|
log_file |
Path | None |
|
verbose |
bool |
|
quiet_console |
bool |
Functions
truncate_str
Truncate a string if it exceeds max_len characters.
truncate_str
def truncate_str(s: str, max_len: int = 500, suffix: str = ' ... (truncated)') -> str
Truncate a string if it exceeds max_len characters.
Parameters 3
| Name | Type | Default | Description |
|---|---|---|---|
s |
str |
— | |
max_len |
int |
500 |
|
suffix |
str |
' ... (truncated)' |
Returns
str
truncate_error
Safely truncate an exception string representation.
truncate_error
def truncate_error(e: Exception, max_len: int = 500) -> str
Safely truncate an exception string representation.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
e |
Exception |
— | |
max_len |
int |
500 |
Returns
str
configure_logging
Configure global logging settings.
configure_logging
def configure_logging(level: LogLevel = LogLevel.INFO, log_file: Path | None = None, verbose: bool = False, track_memory: bool = False) -> None
Configure global logging settings.
Parameters 4
| Name | Type | Default | Description |
|---|---|---|---|
level |
LogLevel |
LogLevel.INFO |
Minimum log level to emit |
log_file |
Path | None |
None |
Path to log file |
verbose |
bool |
False |
Show verbose output |
track_memory |
bool |
False |
Enable memory profiling (adds overhead) |
get_logger
Get or create a logger instance.
get_logger
def get_logger(name: str) -> BengalLogger
Get or create a logger instance.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
name |
str |
— | Logger name (typically name) |
Returns
BengalLogger instanceBengalLogger
—
set_console_quiet
Enable or disable console output for all loggers.
Used by live progress manager to suppress struct…
set_console_quiet
def set_console_quiet(quiet: bool = True) -> None
Enable or disable console output for all loggers.
Used by live progress manager to suppress structured log events while preserving file logging for debugging.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
quiet |
bool |
True |
If True, suppress console output; if False, enable it |
close_all_loggers
Close all logger file handles.
close_all_loggers
def close_all_loggers() -> None
Close all logger file handles.
reset_loggers
Close all loggers and clear the registry (for testing).
reset_loggers
def reset_loggers() -> None
Close all loggers and clear the registry (for testing).
print_all_summaries
Print timing and memory summaries from all loggers.
print_all_summaries
def print_all_summaries() -> None
Print timing and memory summaries from all loggers.