tslog
tslog copied to clipboard
Add prettyLogLevelMethod for routing log levels to specific console methods
This PR introduces the prettyLogLevelMethod setting to tslog, allowing users to map log levels to specific console methods (such as console.warn, console.error, etc.) when using "pretty" log output.
Features
prettyLogLevelMethod option:
- Allows mapping each log level (
INFO,WARN,ERROR, etc.) to a different console function.
Supports "*" fallback:
- The
"*"key acts as a catch-all for unmapped levels.
Log level-aware default console routing:
- If
prettyLogLevelMethodis not provided, tslog will fall back to console.log, matching previous behavior.
Example
const logger = new Logger({
type: "pretty",
prettyLogLevelMethod: {
TRACE: console.trace,
DEBUG: console.debug,
INFO: console.info,
WARN: console.warn,
ERROR: console.error,
FATAL: console.error,
"*": console.log,
},
});
Documentation
The README has been updated to document the prettyLogLevelMethod option and provide usage examples.
Closes This MR addresses Feature Request: Respect log level when writing to console #325