Custom Formatting
Create custom log message formats
Customize log message formats using placeholders to match your logging needs.
If you omit customLogFormat, Logixlysia uses a built-in default that includes the fox {icon}, optional {service} prefix, colored method and duration, {speed} for slow requests, and other common fields.
Basic Usage
logixlysia({
config: {
customLogFormat: '{now} {level} {duration}ms {method} {pathname} {status}'
}
})Available Placeholders
| Placeholder | Description |
|---|---|
{now} | Current date and time |
{level} | Log level (DEBUG, INFO, WARNING, ERROR); with colors, level-colored background chip |
{duration} | Request duration (e.g. 12ms, 1.5s); with colors, green / yellow / red based on slowThreshold and verySlowThreshold |
{method} | HTTP method (padded in the default format) |
{pathname} | Request path (alias: {path}) |
{status} | Response status code |
{statusText} | Status text from Nodeβs http.STATUS_CODES (e.g. Not Found for 404) |
{message} | Custom message |
{icon} | Logixlysia fox π¦; plain emoji when useColors is off or output is not a TTY; with colors on a TTY, a level-colored background around the fox (green INFO, yellow WARNING, red ERROR, blue DEBUG) |
{speed} | When duration β₯ verySlowThreshold, appends β‘ slow (yellow with colors) |
{service} | From config.service, rendered as [name] (dim with colors); empty if unset |
{context} | JSON string of data.context when the context tree is off or context is empty; omitted on the main line when the context tree is shown (see below) |
{ip} | Client IP address (from x-forwarded-for or x-real-ip; empty when testing locally without these headers) |
{epoch} | Unix timestamp |
Examples
Minimal Format
customLogFormat: '{method} {pathname} {status}'Output:
GET /api/users 200Branded line with {icon} and {service}
Use {icon} for the Logixlysia fox (level styling applies when colors and a TTY are available). Pair with service in config:
logixlysia({
config: {
service: 'my-api',
customLogFormat: '{now} {service}{icon} {method} {pathname} {status} {duration} {message}{speed}'
}
})With useColors: false or non-TTY output, a line can look like:
2025-04-13T15:00:19.123Z [my-api]π¦ GET /api/users 200 12ms User viewed profileOn a color terminal, the fox appears inside a colored chip by level, and slow requests append β‘ slow via {speed} when duration β₯ verySlowThreshold (default 1000).
Status text
customLogFormat: '{method} {pathname} {status} {statusText}'Example values: 404 Not Found, 500 Internal Server Error.
Timestamp Format
Configure timestamp format separately:
logixlysia({
config: {
customLogFormat: '{now} {level} {method} {pathname}',
timestamp: {
translateTime: 'yyyy-mm-dd HH:MM:ss'
}
}
})Context tree
When showContextTree is true (default), object context passed to logger.info / warn / error / debug is printed under the main line as tree branches, instead of being inlined into {context} on that line.
- Each row is two spaces,
ββorββ, the key (cyan when colors are on), two spaces, then the value. - For
ERRORlogs, anerrorrow is appended when an error object is present (parsed message). - Set
contextDepth(default1) to flatten nested objects into dotted keys (e.g.user.id) up to that depth.
logixlysia({
config: {
showContextTree: true,
contextDepth: 2
}
})Example (no ANSI colors), after a main line like β¦ GET /orders 500 3ms Checkout failed:
ββ orderId ord_123
ββ error Card declinedSet showContextTree: false to disable the tree and put stringified context back on the main line via {context} when you include that token.
Error Log Formatting
The customLogFormat applies to both regular access logs and error logs. When an error occurs (like validation errors or exceptions), the same formatting rules apply, ensuring consistent log output across all log levels.
Best Practices
- Keep formats concise for readability
- Include essential information only
- Use consistent formatting across environments
- Consider log parsing requirements when designing formats
- Error logs will include the error message in the
{message}placeholder