JSON Structured Logs
Metoro automatically detects and parses JSON-formatted logs. When a log entry is in JSON format, Metoro will:- Extract all fields from the JSON object
- Flatten nested JSON structures using dot notation
- Index all fields for searching
- Handle the message field specially
- Extract and index these fields:
service: "payment-processor"
region: "us-west"
error.code: "500"
error.details: "Database connection failed"
- Use the
msg
field as the main log message - Make all fields searchable using attribute filters
error.code = "500"
service = "payment-processor"
error.details = regex: .*connection.*
Message Field Handling
For JSON-formatted logs, Metoro looks for a dedicated message field in this order:msg
fieldmessage
field- If neither exists, the entire JSON object is preserved as the log body
Make sure to include a
msg
or message
field in your JSON logs for better readability.
Move all other fields to log attributes for easy searching- Log Message: “Failed to process order”
- Log Attributes:
timestamp: "2024-03-15T10:30:00Z"
level: "error"
service: "order-service"
order_id: "12345"
error_code: "500"
LogZero Format
Metoro also supports the LogZero format, which follows this pattern:level
: Log level (I=info, D=debug, W=warning, E=error, C=critical)module
: The module nameline
: The line number- Remaining text:
- Becomes the log message if the message is not JSON-formatted
- Is parsed as JSON if the message is JSON-formatted
Best Practices
- Use Consistent Formats: Stick to a consistent log format across your services
- Include Essential Fields: Always include:
- Timestamp
- Service name
- Log level/severity
- A clear message field
- Structured Data: Use JSON formatting for logs when possible
- Nested Data: Feel free to use nested JSON objects - Metoro will flatten them automatically
- Field Naming: Use clear, consistent field names across your services
Searching Structured Logs
You can search through structured log fields using:- Exact matches:
field = "value"
- Regex matches:
field = regex: pattern
- Multiple values:
field = ["value1", "value2"]
- Nested fields:
parent.child = "value"