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

Add check to filter log level #24

Open
winston0410 opened this issue Aug 10, 2023 · 2 comments
Open

Add check to filter log level #24

winston0410 opened this issue Aug 10, 2023 · 2 comments

Comments

@winston0410
Copy link

Is this feature in relation to a problem?

I want to use an env variable to filter log by level. For example, when I use LOG_LEVEL=error, I dont want to see log in level debug.

Describe the solution you'd like

Provide a setup function like enable, so it does not read env var initially, but user can pass env var to it

Alternative

No response

Additional context

No response

@maraisr
Copy link
Owner

maraisr commented Aug 11, 2023

Hi, thanks for the issue! 👋

Wondering, would something like this work for you?

// file: logger.ts

import { defaultReporter, _diary } from 'diary';
import { compare } from 'diary/utils';

export const diary = (name: string) => _diary(name, event => {
  if (compare(event.level, process.env.LOG_LEVEL) return defaultReporter(event);
});

alternatively, leave it with me! Ill have to have a think about a possible api.

@winston0410
Copy link
Author

Hey thanks for coming back, and I think that would work. But I notice that defaultReporter is not exported from diary, only default_reporter?

And yes it would be better if there is a dedicate API that only requires user to change a property to affect which log level to use

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

No branches or pull requests

2 participants