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

The threshold property at appenderlevel wont work or did not exist yet #1358

Open
tanujvishnoi opened this issue Jan 11, 2023 · 3 comments
Open

Comments

@tanujvishnoi
Copy link

tanujvishnoi commented Jan 11, 2023

I am looking for flushing different Appenders logs as per level . In the log4j there was originally a concept of threshold , which actually helps to difne a log level limit at appender level, here the same is not working

    appenders: {
        console: {
            type: 'console', layout: {
                type: 'pattern',
                pattern: '[%p] [%d] [%f{1} line %l] %m'
            },
            threshold: "info"
        },
        file: {
            type: 'file', layout: {
                type: 'pattern',
                pattern: '[%p] [%d] [%f{1} line %l] %m',
            }, filename: path.join(dir, "./logs/app.log")
        }
    },

or is this workaround for that, i dont want to use multiple categories or any alternative to divide logs using a single category

@lamweili
Copy link
Contributor

Hi, there is a logLevelFilter appender that you might want to take a look at.

The below code goes into the filterErrors appender (logLevelFilter).
It then outputs to the logToFile appender (file).

log4js.configure({
  appenders: {
    console: { type: "stdout" },
    logToFile: { type: "file", filename: "only-errors.log" },
    filterErrors: {
      type: "logLevelFilter",
      appender: "logToFile", // output to logToFile appender
      level: "error",
    },
  },
  categories: {
    default: { appenders: ["filterErrors", "console"], level: "debug" },
  },
});

@lamweili
Copy link
Contributor

Hi @tanujvishnoi, did it resolve the issue?

1 similar comment
@lamweili
Copy link
Contributor

Hi @tanujvishnoi, did it resolve the issue?

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