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 8471943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:56:01+00:00 2026-06-10T16:56:01+00:00

I am using log4j for logging. I have a scenario where I have to

  • 0

I am using log4j for logging. I have a scenario where I have to use seperate logging for different severity. For example, for package foo I have to print messages with severity ERROR in the console whereas I have to print messages with severity WARN in log file. How can I configure my log4j.xml for the same.

  • 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-06-10T16:56:02+00:00Added an answer on June 10, 2026 at 4:56 pm

    You may use LevelMatchFilter for your task. Also you should not forget to use another filter – DenyAllFilter – as the last filter in the chain of filters.

    Your log4j.xml will look like this:

    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
        <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
            <layout class="org.apache.log4j.SimpleLayout" />
            <filter class="org.apache.log4j.varia.LevelMatchFilter">
                <param name="LevelToMatch" value="ERROR" />
                <param name="AcceptOnMatch" value="true" />
            </filter>
            <filter class="org.apache.log4j.varia.DenyAllFilter" />     
        </appender>
    
        <appender name="fileAppender" class="org.apache.log4j.FileAppender">
            <param name="File" value="error.log" /> 
            <layout class="org.apache.log4j.SimpleLayout" />
            <filter class="org.apache.log4j.varia.LevelMatchFilter">
                <param name="LevelToMatch" value="WARN" />
                <param name="AcceptOnMatch" value="true" />
            </filter>
            <filter class="org.apache.log4j.varia.DenyAllFilter" />     
        </appender>
    
        <logger name="foo">
             <level value="WARN" />
             <appender-ref ref="consoleAppender" />
             <appender-ref ref="fileAppender" />
        </logger>
    </log4j:configuration>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been told to use log4j for my logging project,but before using log4j,
I have discovered some issues in my program. I was using log4j for logging,
We have multiple batch jobs and using log4j for logging for each on of
I am using log4j for logging. I have a requirement where the log files
My Application is using logging in two manner....1) programatic 2) log4j.xml I have to
We have to introduce logging in our application. We have decided to use log4j
I am using Jacorb 3.0 and I want to use log4j as the logging
I have multiple applications using log4j for their logging, each loading settings from separate
I have a web application that dumps logging information in a file using log4j
I have a project using common-logging and log4j , I want to change to

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.