This document provides comprehensive documentation for the ESP-IDF logging system, including log
generation, management, analysis, and integration with all scripts.
π Table of Contents
π Overview
The ESP-IDF logging system provides comprehensive log capture, management,
and analysis capabilities for all development operations.
It features automatic log generation, intelligent organization, powerful search capabilities,
and seamless integration with the build and flash systems.
Core Features
Automatic Log Generation: Built-in logging for all script operations
Intelligent Organization: Structured log file naming and organization
Comprehensive Capture: Complete capture of build, flash, and monitor output
Advanced Search: Cross-log search and pattern matching capabilities
Automatic Rotation: Smart log management with configurable retention
Key Capabilities
Automatic log file creation with timestamped naming
## Rotation policies
- Maximum log files: 50 (configurable)
- Retention period: 30 days (configurable)
- Archive old logs automatically
- Clean up expired logs
Cleanup Operations
1
2
3
4
5
6
7
8
9
## Manual cleanup
./manage_logs.sh clean 7 # Keep logs for 7 days
./manage_logs.sh clean 30 # Keep logs for 30 days
./manage_logs.sh clean # Use default retention## Automatic cleanup
- Daily cleanup of expired logs
- Archive creation for old logs
- Storage optimization
Log File Management
File Operations
1
2
3
4
5
6
7
8
9
10
11
## List all logs
./manage_logs.sh list
## View specific log
./manage_logs.sh view gpio_test_Release_20250115_143022.log
## Show latest log
./manage_logs.sh latest
## Get log statistics
./manage_logs.sh stats
Storage Optimization
1
2
3
4
5
## Storage features
- Automatic compression of old logs
- Efficient file organization
- Configurable retention policies
- Storage usage monitoring
π Log Analysis and Search
Cross-Log Search
Pattern Search
1
2
3
4
5
6
7
8
9
10
## Search for specific patterns
./manage_logs.sh search "ERROR"# Find all errors
./manage_logs.sh search "WARNING"# Find all warnings
./manage_logs.sh search "FAILED"# Find all failures
./manage_logs.sh search "SUCCESS"# Find all successes## Advanced search patterns
./manage_logs.sh search "gpio.*error"# GPIO-related errors
./manage_logs.sh search "flash.*failed"# Flash failures
./manage_logs.sh search "build.*success"# Build successes
Search Capabilities
The search system provides powerful capabilities:
1
2
3
4
5
6
7
## Search features
- Regular expression support
- Case-insensitive search
- Multi-line pattern matching
- Context display
- Result highlighting
- Search result summary
Log Statistics and Analysis
Statistical Analysis
1
2
3
4
5
6
7
8
9
10
## Get log statistics
./manage_logs.sh stats
## Statistics include
- Total log files
- Total log size
- Log age distribution
- Error frequency
- Success rates
- Performance metrics
## Compare different logs
./manage_logs.sh compare log1.log log2.log
## Comparison features
- Side-by-side comparison
- Difference highlighting
- Common pattern identification
- Change tracking
π Usage Examples and Patterns
Basic Log Management
1. View Logs
1
2
3
4
5
6
7
8
## List all available logs
./manage_logs.sh list
## View the most recent log
./manage_logs.sh latest
## View a specific log file
./manage_logs.sh view gpio_test_Release_20250115_143022.log
2. Search Logs
1
2
3
4
5
6
7
8
9
## Search for errors
./manage_logs.sh search "ERROR"## Search for specific patterns
./manage_logs.sh search "build.*failed"
./manage_logs.sh search "flash.*success"## Search with context
./manage_logs.sh search "gpio.*error"--context 5
3. Log Maintenance
1
2
3
4
5
6
7
8
9
## Clean old logs
./manage_logs.sh clean 7 # Keep 7 days
./manage_logs.sh clean 30 # Keep 30 days## Get log statistics
./manage_logs.sh stats
## Archive old logs
./manage_logs.sh archive
Advanced Log Patterns
1. Development Workflow Logging
1
2
3
4
5
6
7
8
9
10
## Complete development workflow with logging
./build_app.sh gpio_test Debug --log
./flash_app.sh flash_monitor gpio_test Debug --log
./manage_logs.sh latest
## Expected result
- Build log with debug information
- Flash log with port detection
- Monitor log with device output
- Comprehensive development trace
2. Production Deployment Logging
1
2
3
4
5
6
7
8
9
10
## Production deployment with logging
./build_app.sh gpio_test Release --log production_build
./flash_app.sh flash gpio_test Release --log production_deploy
./manage_logs.sh search "production.*success"## Expected result
- Production build log
- Deployment log
- Success verification
- Audit trail for production
## Enable log debug modeexport LOG_DEBUG=1
export LOG_VERBOSE=1
## Check log system status
./manage_logs.sh --help
./manage_logs.sh list --verbose## Debug information available
- Log file creation details
- Log capture process information
- Log organization details
- Search and analysis information
Problem: Log files are very large and slow to process
Symptoms: Slow search operations or high memory usage
Solutions:
1
2
3
4
5
6
7
8
9
10
11
## Check log file sizes
./manage_logs.sh list | xargs ls-lh## Compress old logs
./manage_logs.sh compress
## Clean old logs
./manage_logs.sh clean 7
## Split large logs
./manage_logs.sh split large_log.log
Search Performance
Problem: Log search operations are slow
Symptoms: Long search times or high CPU usage
Solutions:
1
2
3
4
5
6
7
8
9
10
11
## Use more specific search patterns
./manage_logs.sh search "ERROR.*gpio"# More specific than just "ERROR"## Limit search scope
./manage_logs.sh search "ERROR"--max-results 100
## Use indexed search (if available)
./manage_logs.sh search "ERROR"--indexed## Search in specific time range
./manage_logs.sh search "ERROR"--since"2025-01-15"
π Reference and Examples
Command Reference
Log Management Commands
1
2
3
4
5
6
7
8
9
10
11
12
./manage_logs.sh [command][options]
## Commands:## list - List all log files with details## view <log_name> - View a specific log file## search <pattern> - Search across all log files## clean [days] - Clean logs older than N days## stats - Show log statistics and summary## latest - Show the most recent log file## compare <log1> <log2> - Compare two log files## archive - Archive old logs## compress - Compress old logs
Log Options
--verbose: Enable verbose output
--context <lines>: Show context lines around search results
--max-results <count>: Limit search results
--since <date>: Search logs since specific date
--until <date>: Search logs until specific date
--help: Show usage information
Environment Variables
1
2
3
4
5
6
7
8
9
## Logging configurationexport LOG_ENABLED=1 # Enable/disable loggingexport LOG_LEVEL=INFO # Set log level (DEBUG, INFO, WARN, ERROR)export LOG_DIR="logs/"# Set log directoryexport LOG_RETENTION_DAYS=30 # Set log retention periodexport LOG_MAX_FILES=50 # Set maximum log filesexport LOG_COMPRESSION=1 # Enable/disable compressionexport LOG_ROTATION=1 # Enable/disable rotationexport LOG_ARCHIVE=1 # Enable/disable archiving
## app_config.yml standard logging configurationflash_config:auto_logging:truelog_rotation:truemax_log_files:50log_retention_days:30log_compression:truelog_archive:truelog_format:"detailed"log_level:"INFO"