Structured Logging
Move beyond plain text logs and unlock the full power of your data with rich metadata.
Why Structured Logging?
Plain text logs are easy for humans to read but hard for machines to parse and analyze. Structured logging turns your logs into searchable, queryable data.
The LuminaLog Edge
Text vs. Structured
logger.info('User 123 logged in from 1.1.1.1');Hard to filter logs by user ID or IP address without complex regex.
logger.info('User login', {
userId: '123',
ipAddress: '1.1.1.1',
method: 'oauth'
});Instantly filter by any field: userId:123
Metadata Best Practices
Consistent Keys
Use the same keys across different logs and services (e.g., use 'userId', not 'user_id' in one place and 'uid' in another).
Flat Structure
Avoid deep nesting. Keep your metadata objects as flat as possible for better search performance.
Include IDs
Always include relevant IDs (request_id, session_id, user_id) to trace actions across your stack.
Appropriate Types
Use numbers for metrics (duration, count) and strings for identifiers or categories.
Child Loggers
LuminaLog SDKs support child loggers. A child logger inherits metadata from its parent, making it easy to attach context to every log in a specific request or module.
// Parent logger with global context
const logger = new LuminaLog({ apiKey, environment: 'prod' });
// Create simple context for a specific request
const requestLogger = logger.child({ requestId: 'abc-123' });
requestLogger.info('Starting checkout');
// Stored with: { requestId: 'abc-123' }