EDSL provides comprehensive log management capabilities through the LogManager class. This powerful tool allows you to filter, analyze, and manage EDSL log files with advanced features for debugging, monitoring, and data analysis.
from edsl.logger import LogManager# Create LogManager instancelog_manager = LogManager()# View overview with statistics and available commandslog_manager
This displays a rich overview of your log file:
LogManager( 📁 Log file: /Users/john/.edsl/logs/edsl.log 📊 Total entries: 9,420 📅 Date range: 2025-08-15 23:40 to 2025-08-16 09:23 📈 Levels: INFO:5471, ERROR:3949 🔍 Top logger: edsl.edsl.coop.coop 💡 Common commands: .get_filtered_entries(level='ERROR', n=50) # Get recent errors .to_scenario_list(level='ERROR', since_hours=24) # Convert to scenarios .analyze_patterns(n=100) # Pattern analysis .archive() # Archive and clear logs .clear() # Clear all log entries)
Convert log entries to EDSL scenarios for advanced analysis:
# Convert logs to scenarioserror_scenarios = log_manager.to_scenario_list(level='ERROR', n=50)# Each log entry becomes a scenario with rich metadatafirst_scenario = error_scenarios[0]print(f"Error level: {first_scenario['level']}")print(f"Timestamp: {first_scenario['timestamp_str']}")print(f"Logger: {first_scenario['logger_module']}")print(f"Message: {first_scenario['message']}")print(f"Is error: {first_scenario['is_error']}")print(f"Hour of day: {first_scenario['hour']}")
Available scenario fields: - timestamp_str: Formatted timestamp - logger_name: Full logger name - logger_module: Last part of logger name - level: Log level (ERROR, INFO, etc.) - level_int: Numeric level for comparison - message: Log message content - raw_line: Original log line - hour, minute, weekday: Time components - date_str: Date in YYYY-MM-DD format - is_error: Boolean for ERROR/CRITICAL levels - is_warning_or_above: Boolean for WARNING+ levels - has_exception: Boolean if message contains “exception” - has_failed: Boolean if message contains “fail” - message_length: Character count of message - words_count: Word count of message
# Clear with confirmation prompt (safe)success = log_manager.clear()# Clear immediately for scripts (use with caution)success = log_manager.clear(confirm=True)
The clear process includes safety confirmation:
⚠️ About to clear EDSL log file: 📁 File: /Users/john/.edsl/logs/edsl.log 📊 Entries: 9,420 ⚠️ This action cannot be undone! Continue? (type 'yes' to confirm):
# Daily error reviewdef daily_error_review(): log_manager = LogManager() # Get yesterday's errors errors = log_manager.get_filtered_entries( level='ERROR', since_hours=24 ) if errors: print(f"Found {len(errors)} errors in last 24 hours:") for error in errors[-5:]: # Show last 5 print(f" {error.timestamp}: {error.message}") # Convert to scenarios for analysis error_scenarios = log_manager.to_scenario_list(entries=errors) # Analyze with EDSL from edsl import QuestionFreeText q = QuestionFreeText( question_name="priority", question_text="Rate the priority of this error (1-5): {{ message }}" ) priorities = q.by(error_scenarios[:10]).run() # Analyze top 10 print(priorities.select("priority").print())
LogManager provides rich HTML displays in Jupyter notebooks:
# In Jupyter notebookfrom edsl.logger import LogManagerlog_manager = LogManager()log_manager # Shows rich HTML table with colored log levels
The HTML display includes: - Overview with file path, entry count, and date range - Color-coded log level distribution (red for errors, blue for info) - Top loggers table with counts - Interactive command examples with syntax highlighting
log_file_path (Path*,* optional) – Optional path to log file. Defaults to ~/.edsl/logs/edsl.log
get_filtered_entries(**kwargs)
Filter log entries by various criteria.
Parameters
• n (int*,* optional) – Maximum number of entries to return • level (strorList*[str]**,* optional) – Specific level(s) to include (‘DEBUG’, ‘INFO’, ‘WARNING’, ‘ERROR’, ‘CRITICAL’) • min_level (str*,* optional) – Minimum level (includes this level and above) • since_hours (float*,* optional) – Include entries from last N hours • since_minutes (float*,* optional) – Include entries from last N minutes • start_date (strordatetime*,* optional) – Start date for filtering (‘YYYY-MM-DD’) • end_date (strordatetime*,* optional) – End date for filtering (‘YYYY-MM-DD’) • pattern (str*,* optional) – Regex pattern for message content • logger_pattern (str*,* optional) – Regex pattern for logger names • case_sensitive (bool*,* optional) – Whether pattern matching is case sensitive • reverse (bool*,* optional) – Return in reverse chronological order
Test filters with small limits: get_filtered_entries(n=10, ...)
The LogManager provides powerful capabilities for understanding, analyzing, and maintaining your EDSL logs. Whether you’re debugging issues, monitoring system health, or conducting research on usage patterns, LogManager offers the tools you need for effective log management.