Skip to content
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

[Draft] @neodx/log - An advanced levels filtering #118

Open
secundant opened this issue Aug 11, 2023 · 0 comments
Open

[Draft] @neodx/log - An advanced levels filtering #118

secundant opened this issue Aug 11, 2023 · 0 comments
Labels
feature New feature or request scope:log Issues related to logger

Comments

@secundant
Copy link
Owner

Currently, users can only specify the max level.

const logger = createLogger({
  level: 'done', // Log up to the "done" level
  target: [
    json(), // Write JSON logs for all levels that are <= "done" (without any additional restrictions)
    {
      level: 'warn', // Exclude logs higher than the "warn" level
      target: json({ target: myFile })
    }
  ] 
});

However, they cannot define the minimum or exclusive logic for them, resulting in the inability to define a flow for unnecessary or specific logs.

For example, we want to redirect all debug logs to the file. Additionally, all logs except for "error" should be sent to stdout, while "error" logs should be directed to stderr.

API Proposal

const logger = createLogger({
  name: 'my-app',
  // Define the global maximum level of logs that will be processed
  level: process.env.NODE_ENV === 'production' ? 'done' : 'debug',
  target: [
    // handle all logs
    handleAllLogs,
    {
      // handle only 'warn' and 'error' logs
      level: 'warn',
      target: handleWarnLogs
    },
    {
      // handle 'warn', 'info' and 'done' logs
      level: { min: 'warn', max: 'done' },
      target: handleRegularLogs
    },
    {
      // handle only 'debug' logs
      level: { min: 'debug', max: 'debug' },
      target: handleDebugLogs
    }
  ]
});
@secundant secundant added feature New feature or request scope:log Issues related to logger labels Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request scope:log Issues related to logger
Projects
None yet
Development

No branches or pull requests

1 participant