Skip to content

Feature Request: add logMeta argument in transportFormatted #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
HairlessVillager opened this issue Apr 24, 2025 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@HairlessVillager
Copy link

Description / Use Case for a Feature

I want to use different log level in console e.g. console.error | warn | info, and your docs gives a example:

const logger = new Logger({
  type: "pretty",
  overwrite: {
    transportFormatted: (logMetaMarkup, logArgs, logErrors) => {
      // Send different log levels to appropriate console methods
      const logLevel = logMetaMarkup.trim().split("\t")[1]; // Extract log level from the markup
      switch (logLevel) {
        case "WARN":
          console.warn(logMetaMarkup, ...logArgs, ...logErrors);
          break;
        case "ERROR":
        case "FATAL":
          console.error(logMetaMarkup, ...logArgs, ...logErrors);
          break;
        case "INFO":
          console.info(logMetaMarkup, ...logArgs, ...logErrors);
          break;
        case "DEBUG":
        case "TRACE":
        case "SILLY":
        default:
          console.log(logMetaMarkup, ...logArgs, ...logErrors);
          break;
      },
  },
});

, which use string operation to know which log level it is.

Obviously, a more elegant way is to add a logMeta parameter to the transportFormatted function, so we can write it like this:

const logger = new Logger({
  type: "pretty",
  overwrite: {
    transportFormatted: (logMeta, logMetaMarkup, logArgs, logErrors) => {
      const logLevel = logMeta.logLevelName;
      switch (logLevel) {
        // ...
      },
  },
});

How about it? I'd like to help implement this feature🥰

@HairlessVillager HairlessVillager added the enhancement New feature or request label Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant