createConsole
Creates a console transport with support for JSON and pretty-printed output.Signature
Parameters
Optional configuration for the console transport
Output format mode:
"json": Outputs logs as JSON strings (default)"pretty": Outputs logs with colors and formatting for better readability
Optional custom format function. When provided, this function is called instead of the default formatting logic. Use this for complete control over the output format.
Returns
ATransport instance that can be used with createLogger.
Example: JSON Mode (Default)
Example: Pretty Mode
Pretty Mode Features
When usingmode: 'pretty', the console transport:
-
Color-codes log levels:
debug: Cyaninfo: Greenwarn: Yellowerror: Red
-
Formats file paths: Shows relative paths and filters out
node_modules - Pretty-prints data: Uses JSON colorization with tree-style borders when additional data is present
- Highlights messages: Uses bold white text for better visibility
Example: Custom Format Function
Example: Multiple Console Transports
Flush Behavior
The console transport implements aflush function that does nothing, since console output is synchronous and doesn’t require buffering. This ensures compatibility with the logger’s flush mechanism.