Logging Daemon (logd)
Overview
The Logging Daemon (logd) provides centralized logging services for FreeWorld OS, collecting and managing log messages from all system components. It handles log rotation, filtering, and archival.
Features
- Log Message Collection: Receives log entries from all system components
- Log File Rotation: Automatically rotates logs when size limit reached
- Log Level Filtering: Filters logs by severity level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
- Log Archival: Maintains multiple rotated log files
- Structured Logging: Timestamp, level, source, PID, and message
- Daemon Mode: Runs as background daemon
Log Levels
| Level | Value | Description |
|---|---|---|
DEBUG |
0 | Debug information (verbose) |
INFO |
1 | Informational messages |
WARNING |
2 | Warning messages |
ERROR |
3 | Error messages |
CRITICAL |
4 | Critical system errors |
Log Format
Log entries are written in the following format:
[YYYY-MM-DD HH:MM:SS] [LEVEL] [SOURCE] [PID:####] Message text
Example:
[2024-01-15 10:30:45] [INFO] [kernel] [PID:1] Kernel initialized successfully
[2024-01-15 10:30:46] [ERROR] [networkd] [PID:42] Failed to configure interface eth0
Configuration
logd can be configured via command-line arguments:
--no-daemon- Run in foreground (for debugging)--log-dir <path>- Set log directory (default: /var/log)--max-size <MB>- Maximum log file size in MB (default: 10MB)--min-level <LEVEL>- Minimum log level to record (default: INFO)
Log Rotation
When a log file reaches the maximum size, logd automatically rotates it:
- Current log (
system.log) is renamed tosystem.log.1 - Existing rotated logs are shifted (
system.log.1→system.log.2, etc.) - Oldest log files beyond the limit are deleted
- A new
system.logis created
Default: Keeps up to 10 rotated log files
IPC Interface
Components send log entries to logd via IPC (stdin in current implementation). The format is:
LEVEL|SOURCE|PID|MESSAGE
Example:
INFO|kernel|1|Kernel initialized
ERROR|networkd|42|Failed to configure interface
Future: Will use Unix domain sockets or named pipes for better IPC
Usage
Starting logd
# Start as daemon (default)
logd
# Start in foreground for debugging
logd --no-daemon
# Custom configuration
logd --log-dir /custom/logs --max-size 50 --min-level WARNING
Sending Log Entries
# From a C program
printf("INFO|myapp|%d|Application started\n", getpid()) | logd
# From shell script
echo "WARNING|script|$$|Disk space low" | logd
File Structure
services/logd/
├── logd.c # Main daemon implementation
└── Makefile # Build system
Integration
logd integrates with:
- Kernel Logger: Receives kernel log messages
- System Services: All services send logs to logd
- Applications: User applications can send logs via IPC
- System Monitor: Can read log files for monitoring
Status
Core Functionality
✅ Complete
✅ Complete
Log Rotation
✅ Complete
✅ Complete
Level Filtering
✅ Complete
✅ Complete
IPC Interface
⚠️ Simplified (stdin), needs sockets/pipes
⚠️ Simplified (stdin), needs sockets/pipes