Normalizer
Before any log is formatted, Logry first passes it through a platform-aware normalizer.
This process ensures a consistent structure, reliable data types, and full flexibility for customization.
What it does​
The Normalizer transforms a raw log payload into a normalized shape, handling core fields like:
- timestamp
- id
- level
- scope
- message
- meta
- context
- pid (Node.js only)
- hostname (Node.js only)
Each field has a dedicated normalizer, all of which can be overridden via custom logic.
Customization​
Every normalizer supports a customNormalizer function, letting you override default behavior:
id: {
customNormalizer: ({ fieldValue, raw }) => `node-${fieldValue}`, // e.g., "default" → "node-default"
// fieldValue: the original value for the "id" field
// raw: a snapshot of the full raw payload before any normalization
}
You can also fine-tune behavior using extra options per field.
Field | Extra Options Available |
---|---|
timestamp | style, useUTC, showTimeOnly |
level | style |
scope | separator |
meta | errorStackLines |
Platform Awareness​
Normalization logic in Logry adapts based on the runtime environment,
allowing logs to be tailored specifically for Node.js or Browser contexts.
For example:
- Timestamps appear as full ISO 8601 UTC strings in Node, but as simplified human-readable strings in the browser.
You can define environment-specific behavior using the normalizerConfig structure.
It can be set globally in logry(...), scoped to a logger.child(...), or overridden per log method:
const logger = logry({
// ...
normalizerConfig: {
node: {
timestamp: {
style: "iso", // Use full ISO format for timestamp in Node.js
useUTC: true, // Display timestamp in UTC timezone
},
level: {
style: "upper", // Show log level in uppercase (e.g., "ERROR")
},
meta: {
errorStackLines: 10, // Limit error stack trace to 10 lines
},
},
browser: {
timestamp: {
style: "pretty", // Use a more human-friendly timestamp format in browsers
useUTC: false, // Display timestamp in local timezone
},
level: {
style: "lower", // Show log level in lowercase (e.g., "error")
},
},
},
// ...
});