Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7405451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:24:24+00:00 2026-05-29T05:24:24+00:00

In log4j most (if not all) appenders extend AppenderSkeleton which provides a setThreshold(Priority) method

  • 0

In log4j most (if not all) appenders extend AppenderSkeleton which provides a setThreshold(Priority) method for setting the minimal “level” that a message must be set to in order for the appender to log it somewhere.

I want to log messages to different appenders based on the exact level/priority of the message.

For instance, I want DEBUG messages to log to a ConsoleAppender, but nowhere else. I want INFO messages to log to a FileAppender and nowhere else. I want ERROR messages to log to a JMSAppender and nowhere else.

The problem is this setThreshold(Priority) method, which sets the “minimal threshold” necessary to log a message.

Sure, I could set the ConsoleAppender‘s threshold to DEBUG, but since INFO and ERROR messages are “higher” than DEBUG messages, I will also get INFO and ERROR messages sent to the ConsoleAppender as well.

Are there are methods or ways of configuring appender “levels”/priorities exactly or is this minimal threshold my only recourse?

Edit using LevelMatchFilter:

Is this a step in the right direction?

LevelMatchFilter filter = new LevelMatchFilter();
filter.setLevelToMatch(Level.DEBUG.toString());

consoleAppender.addFilter(filter);

Would that code snippet above accomplish the job of making sure the ConsoleAppender logs DEBUGs, and only DEBUGs?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:24:25+00:00Added an answer on May 29, 2026 at 5:24 am

    You can attach a LevelMatchFilter to any appender to filter log messages by only the exact level.

    From the javadoc:

    This is a very simple filter based on level matching.

    The filter admits two options LevelToMatch and AcceptOnMatch. If there is an exact match between the value of the LevelToMatch option and the level of the LoggingEvent, then the decide(org.apache.log4j.spi.LoggingEvent) method returns Filter.ACCEPT in case the AcceptOnMatch option value is set to true, if it is false then Filter.DENY is returned. If there is no match, Filter.NEUTRAL is returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which log4j appender should I use and how do I configure it? I'm not
I am using log4j for my application - there I need to see all
Using log4j on Unix, which Appender would perform the best to write 1000Meg :
I'm trying to use log4j to handle the logs for a web-service which is
I have log4j.xml as below but it is logging messages at ERROR level. Can
I catch NullPointerException but log4j does not print stack trace, I aspect number of
I have a log4j properties file which is creating a file inside my tomcat>bin
Whether it be java.util.logging, commons-logging, log4j, and even the most recent slf4j and logback,
Am using my java application with log4j as logging mechanism For most of the
Which log4j Version is bundled with latest OpenCms 7?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.