This logging system is built-in to TerminalOS and requires no additional setup:
git clone https://github.com/NatBuilds/TerminalOS.git
cd TerminalOS
pip install -r requirements.txt
python run.pyA comprehensive file-based logging system automatically captures all application activity. All messages (info, warnings, errors, success, debug) are logged to timestamped files in the logs/ directory.
Session logs are created automatically when the application starts, one per session.
- Every status message is automatically logged to file
- Timestamped entries for easy tracking
- Session-based log files (one file per application session)
- Graceful handling of logging errors (doesn't break the app)
- Dedicated Logs menu module for viewing and managing logs
- Search functionality to find specific messages
- Error/warning summary views
- Session statistics tracking
- Automatic cleanup of old logs (>30 days)
- Session start time
- Total duration
- Message counts (total, errors, warnings)
- Log file location
All logs are stored in: {project_root}/logs/
Each session creates a file named: session_YYYYMMDD_HHMMSS.log
Example: session_20260428_110735.log
Run the application and navigate to: Logs
Options available:
- View current session logs - Show all messages from this session
- View session statistics - Timing and message counts
- View error summary - All errors and warnings
- Search logs - Find specific messages
- View all log files - List all session logs
- Show logs directory - Display logs folder location
- Clear old logs - Delete logs older than 30 days
from app.libraries.logging import get_logger, log_info, log_error
# Log a message
log_info("Application started")
log_error("Something failed")
# Get logger instance
logger = get_logger()
print(f"Messages logged: {logger.message_count}")
print(f"Errors: {logger.error_count}")All status messages are automatically logged:
from app.core import status
status.info("This gets logged")
status.error("Errors are logged")
status.warning("Warnings are logged")
status.success("Success messages are logged")
status.debug("Debug messages are logged (if verbose enabled)")from app.libraries.logging import log_info, log_error, log_warning, log_success
log_info("Custom message")
log_error("Error with context", error_code="E001", severity="high")Session summary is automatically written when the app exits:
================================================================================
Session Summary
================================================================================
Total Messages: 127
Errors: 3
Warnings: 8
Duration: 45.3 seconds
End Time: 2026-04-28 11:12:00
================================================================================
Each log file contains:
================================================================================
TerminalOS Session Log
Started: 2026-04-28 11:11:15
================================================================================
11:11:16.234 [INFO] Application started
11:11:17.101 [SUCCESS] Connected to device
11:11:18.502 [DEBUG] Executing command: adb shell
11:11:19.003 [ERROR] Failed to capture screenshot
...
HH:MM:SS.mmm [LEVEL] Message text
- HH:MM:SS.mmm - Time with millisecond precision
- [LEVEL] - Message level: INFO, WARNING, ERROR, SUCCESS, DEBUG
- Message text - The actual message
Important messages may include additional context:
11:11:19.003 [ERROR] Failed to capture screenshot
error_code: E001
device: X5BDU19115000764
reason: file_not_created
- Logs are kept indefinitely by default
- Old logs are not deleted automatically
Use the Logs menu → Clear old logs to delete logs older than 30 days
Or programmatically:
import time
from pathlib import Path
cutoff_time = time.time() - (30 * 24 * 60 * 60) # 30 days ago
for log_file in Path("logs").glob("*.log"):
if log_file.stat().st_mtime < cutoff_time:
log_file.unlink()Track session performance:
from app.libraries.logging import get_stats
stats = get_stats()
print(f"Total messages: {stats['total_messages']}")
print(f"Errors: {stats['errors']}")
print(f"Warnings: {stats['warnings']}")
print(f"Duration: {stats['elapsed_seconds']} seconds")- Check directory permissions:
logs/should be writable - Check disk space: ensure enough space for log files
- Verify logging module is imported
- Use menu option Clear old logs regularly
- Or manually delete
logs/*.logfiles
Logging is designed to be minimal overhead:
- Errors don't interrupt normal operation
- Logging happens on same thread (non-blocking)
- File writes are buffered
Main Menu → Logs → View error summary
Shows all errors from the current session with timestamps.
Main Menu → Logs → Search logs
Enter search term: X5BDU19115000764
Finds all messages mentioning the specific device.
Main Menu → Logs → View session statistics
Displays timing information and message counts.
from app.libraries.logging import log_info, log_error
def my_feature():
log_info("Feature started", feature="my_feature")
try:
# Do something
log_info("Feature completed successfully")
except Exception as exc:
log_error(f"Feature failed: {exc}", feature="my_feature", traceback=str(exc))from pathlib import Path
log_file = Path("logs/session_20260428_110735.log")
with open(log_file, "r") as f:
for line in f:
if "[ERROR]" in line:
print(f"Error: {line.rstrip()}")from collections import Counter
from pathlib import Path
log_dir = Path("logs")
error_counts = Counter()
for log_file in log_dir.glob("*.log"):
with open(log_file, "r") as f:
for line in f:
if "[ERROR]" in line:
error_counts[log_file.name] += 1
for session, count in error_counts.most_common():
print(f"{session}: {count} errors")app/core/status.py- All messages automatically logged
app/main.py- Session summary written on exit
app/libraries/logging/- Core logging functionality
app/modules/logs/- Interactive menu for log management
- File I/O: Logs are written synchronously (could add buffering in future)
- Disk Space: Monitor
logs/directory size - Session Duration: Longer sessions = larger log files
-
Use appropriate log levels
INFOfor normal operationsWARNINGfor recoverable issuesERRORfor failuresDEBUGfor diagnostic information
-
Include context when logging errors
- Device serial number
- Operation being performed
- Relevant parameters
-
Review logs regularly for patterns and issues
-
Clean up old logs periodically to save disk space
-
Use search to quickly find specific issues
The logging system provides comprehensive tracking of all application activity. Use the Logs menu to view, search, and manage logs efficiently. All status messages are captured automatically for later review and troubleshooting.