Skip to content

Conversation

@aelesia
Copy link

@aelesia aelesia commented Nov 22, 2025

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 prettyLogLevelMethod is 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant