diary icon indicating copy to clipboard operation
diary copied to clipboard

Add check to filter log level

Open winston0410 opened this issue 2 years ago • 2 comments

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

winston0410 avatar Aug 10 '23 10:08 winston0410

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.

maraisr avatar Aug 11 '23 23:08 maraisr

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

winston0410 avatar Aug 12 '23 07:08 winston0410