Enhanced the Docker logs API to support historical log persistence, severity filtering, date range queries, and search capabilities.
| Parameter | Type | Values | Default | Description |
|---|---|---|---|---|
source |
string | live, historical, both |
live |
Log source selection |
severity |
string | TRACE, DEBUG, INFO, WARN, ERROR, FATAL |
- | Filter by severity level |
startDate |
ISO date | - | - | Start date for historical logs |
endDate |
ISO date | - | - | End date for historical logs |
limit |
number | 1-10000 | 1000 | Maximum logs to retrieve |
search |
string | - | - | Search term (max 500 chars) |
tail |
number | 10-10000 | 100 | Lines from live Docker logs |
timestamps |
string | true, false |
true |
Include timestamps in live logs |
since |
number | Unix timestamp | - | Live logs since timestamp |
until |
number | Unix timestamp | - | Live logs until timestamp |
{
"success": true,
"msg": "Docker logs retrieved successfully",
"data": {
"logs": [
{
"timestamp": "2025-01-14T10:30:45.123Z",
"severity": "ERROR",
"message": "Database connection failed",
"rawLog": "2025-01-14 10:30:45 [ERROR] Database connection failed",
"containerId": "abc123...",
"containerName": "my-app",
"monitorId": "507f1f77bcf86cd799439011",
"isLive": true,
"confidence": 95,
"metadata": {
"pattern": "syslog"
}
}
],
"count": 42,
"source": "both",
"severityStats": {
"ERROR": 15,
"WARN": 12,
"INFO": 10,
"DEBUG": 5
},
"filters": {
"severity": "ERROR",
"startDate": "2025-01-14T00:00:00Z",
"endDate": "2025-01-14T23:59:59Z",
"search": null
}
}
}- MongoDB Storage: Logs stored with TTL index (30 days default)
- Snapshot Grouping: Logs grouped by
snapshotId(UUID v4) - Capture Reasons:
monitor_down,monitor_up,manual,scheduled,error_threshold - Automatic Saving: Triggered on monitor status changes
Supports 8+ log formats with confidence scoring:
- JSON Logs: Winston, Bunyan, Pino (100% confidence)
- Syslog: Standard RFC 5424 format (95% confidence)
- Log4j: Java logging format (90% confidence)
- Docker: Container-specific formats (85% confidence)
- Nginx: Access/error logs (80% confidence)
- Keyword Matching: Fallback detection (70% confidence)
TRACE(0) - Most verboseDEBUG(1) - Debug informationINFO(2) - Informational messagesWARN(3) - Warning conditionsERROR(4) - Error conditionsFATAL(5) - Critical failuresUNKNOWN(99) - Could not determine
- Severity Filtering: Single severity level or minimum threshold
- Date Range: ISO 8601 date strings with validation
- Full-Text Search: MongoDB text index on message + rawLog
- Pagination: Configurable limit (1-10,000 logs)
- Live Only: Direct from Docker API (real-time)
- Historical Only: From MongoDB (persisted logs)
- Both: Merged and sorted by timestamp (newest first)
Live logs automatically enriched with:
- Parsed severity level
- Timestamp extraction
- Confidence score
- Metadata (parsing pattern used)
- Container information
- Monitor ID reference
-
server/src/db/v1/models/DockerLog.js(230 lines)- Mongoose schema with indexes
- Static query methods
- TTL index for automatic cleanup
-
server/src/utils/logParser.js(420 lines)- Multi-format severity detection
- Timestamp extraction
- Message cleaning utilities
-
server/src/service/v1/infrastructure/dockerLogService.js(350 lines)saveLogSnapshot()- Bulk insert with parsinggetHistoricalLogs()- Filtered queriesgetSeverityStats()- AggregationautoSaveOnStatusChange()- Event-driven capture
-
server/src/controllers/v1/monitorController.js- Enhanced
getDockerLogs()method (140 lines) - Dependency injection for
dockerLogService - Live + historical log merging
- Enhanced
-
server/src/validation/joi.js- Added
getDockerLogsQueryValidationschema - Validates all query parameters
- Date range validation
- Added
-
server/src/config/services.js- Instantiated
dockerLogService - Added to dependency injection
- Instantiated
-
server/src/config/controllers.js- Injected
dockerLogServiceintoMonitorController
- Injected
-
server/tsconfig.json- Excluded
test/andcoverage/directories
- Excluded
{
monitorId: ObjectId, // Reference to Monitor
teamId: ObjectId, // Reference to Team
containerId: String, // Docker container ID
containerName: String, // Container name
timestamp: Date, // Log timestamp (indexed)
severity: String, // Enum: TRACE|DEBUG|INFO|WARN|ERROR|FATAL|UNKNOWN
message: String, // Cleaned message (text indexed)
rawLog: String, // Original log line (text indexed)
metadata: {
pattern: String, // Parser pattern used
confidence: Number, // 0-100
extractedFields: Mixed // Additional parsed data
},
captureReason: String, // Enum: monitor_down|monitor_up|manual|scheduled|error_threshold
snapshotId: String, // UUID v4 for grouping
createdAt: Date, // Auto-generated
updatedAt: Date // Auto-generated
}- Compound:
{ monitorId: 1, timestamp: -1 } - Compound:
{ teamId: 1, createdAt: -1 } - Compound:
{ snapshotId: 1, timestamp: -1 } - Single:
{ severity: 1 } - Single:
{ captureReason: 1 } - TTL:
{ createdAt: 1 }(expires after 30 days) - Text:
{ message: "text", rawLog: "text" }
GET /api/v1/monitors/507f1f77bcf86cd799439011/docker-logs?source=live&tail=200GET /api/v1/monitors/507f1f77bcf86cd799439011/docker-logs?source=historical&severity=ERROR&startDate=2025-01-01&endDate=2025-01-14GET /api/v1/monitors/507f1f77bcf86cd799439011/docker-logs?source=historical&search=database%20connection&limit=50GET /api/v1/monitors/507f1f77bcf86cd799439011/docker-logs?source=both&severity=WARN&limit=500- Compound Indexes: Fast queries on monitorId + timestamp
- TTL Index: Automatic cleanup prevents unbounded growth
- Text Index: Efficient full-text search
- Pagination: Prevents large result sets
- Lean Queries: Returns plain objects (not Mongoose documents)
- Maximum logs per request: 10,000
- Search query max length: 500 characters
- Default retention: 30 days (configurable via TTL)
- Live log tail max: 10,000 lines
AUTO_SAVE_DOCKER_LOGS=true # Enable auto-saving (default: true)
DOCKER_LOG_RETENTION_DAYS=30 # TTL in days (default: 30)
DOCKER_LOG_ERROR_THRESHOLD=10 # Error count to trigger save- Monitor Status Change: DOWN → saves last N logs
- Monitor Recovery: UP → saves recovery logs
- Manual Capture: API endpoint for on-demand snapshots
- Scheduled Snapshots: Cron job for periodic captures
- Error Threshold: Saves when error count exceeds limit
- Severity Filter Chips: MUI Chips with color coding
- Date Range Picker: Material-UI DateRangePicker
- Export Functionality: JSON/CSV download buttons
- Log Formatting: Syntax highlighting and line numbers
- Real-time Updates: WebSocket or SSE integration
- Integration tests for Docker operations
- Log parsing accuracy tests (all 8 formats)
- Database query performance tests
- End-to-end workflow tests
- CI/CD pipeline setup
- Old API behavior preserved when no new params used
source=liveis default (matches old behavior)- Existing Docker monitors require no changes
None - all enhancements are additive.
- Team-based authorization enforced
- Monitor access verified before log retrieval
- Search queries sanitized to prevent injection
- TTL index prevents data accumulation
- Configurable retention policy per deployment
- Manual cleanup methods available
- Request limits prevent resource exhaustion
- Pagination enforces maximum result sizes
- Background saves don't block monitor checks
Version: 1.0
Date: 2025-10-11
Author: Keonramses
Status: API Complete - Frontend Complete