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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:05:33+00:00 2026-05-11T19:05:33+00:00

I want to set up log4j so that all log meessages produced from classes

  • 0

I want to set up log4j so that all log meessages produced from classes under package com.foo.bar go to bar.log, and all the log meessages produced from classes under package com.bar.blatz go to blatz.log.

Questions

  • How do I do this using log4j.xml?
  • I know its possible using property files, but how do I do it using the XML configuration?
  • 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-11T19:05:33+00:00Added an answer on May 11, 2026 at 7:05 pm

    This is based on my answer to a similar question:

    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
        <!-- general application log -->
        <appender name="BarLogFile" class="org.apache.log4j.FileAppender">
            <param name="File" value="bar.log" />
            <param name="Threshold" value="INFO" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%-5p %t [%-40.40c] %x - %m%n"/>
            </layout>
        </appender> 
    
        <!-- additional fooSystem logging -->
        <appender name="BlatzLogFile" class="org.apache.log4j.FileAppender">
            <param name="File" value="blatz.log" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%-5p %t [%-40.40c] %x - %m%n"/>
            </layout>
        </appender>
    
        <logger name="com.foo.bar">
            <appender-ref ref="BarLogFile"/>
        </logger>
    
        <logger name="com.bar.blatz">
            <appender-ref ref="BlatzLogFile"/>
        </logger>
    
        <root>
            <level value="INFO"/>
            <!-- no appender, output will be swallowed (I think) -->
        </root>
    </log4j:configuration>
    

    If you add an appender-ref to the root element, it will also receive com.foo.bar etc messages. You can stop that by specifying ‘additivity=”false”‘ on the loggers.

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

Sidebar

Related Questions

I have a subclass from control and I want set text for that. When
I want to set up my log4j log path with a db param. My
I want set progress bar until the next activity start.That mean i want to
In my app, everytime it go in background I want set all classes at
I want to do syslogging from Java. There is a log4j appender, but it
I want set result to variable from MVC controller method. function someFunction(){ var result;
How do I set the log4j configuration to log level DEBUG only for my
We are using Log4j in our project for logging. I want to log some
We use Log4j (and Commons Logging) to log our error messages. Now we want
I use log4j for logging and i want to print all logger.debug statements in

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.