Skip to content

Add prettyLogLevelMethod for routing log levels to specific console methods#330

Merged
terehov merged 1 commit into
fullstack-build:masterfrom
aelesia:prettyLogLevelMethod
Jul 7, 2026
Merged

Add prettyLogLevelMethod for routing log levels to specific console methods#330
terehov merged 1 commit into
fullstack-build:masterfrom
aelesia:prettyLogLevelMethod

Conversation

@aelesia

@aelesia aelesia commented Nov 22, 2025

Copy link
Copy Markdown

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

@terehov
terehov merged commit 32a9a0a into fullstack-build:master Jul 7, 2026
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.

2 participants