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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:35:05+00:00 2026-06-06T19:35:05+00:00

I would like to have two different log4j loggers in my application, and for

  • 0

I would like to have two different log4j loggers in my application, and for there to be no “overlap” between the content they write to their respect logs.

For example:

  • Logger1 writes INFO events related to one set of system events
  • Logger2 writes INFO events related to another set of system events
  • No entry should appear in the log twice

My log4j.properties is as follows:

log4j.rootLogger=DEBUG, stdout
log4j.logger.org.apache=DEBUG, stdout
log4j.logger.xdasLogger=DEBUG, xdas

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%m%n

log4j.appender.xdas=org.apache.log4j.ConsoleAppender
log4j.appender.xdas.layout=org.apache.log4j.PatternLayout
log4j.appender.xdas.layout.ConversionPattern=%d %-5p %c - %m%n

My Java code is as follows:

public static void main(String[] args) {
    PropertyConfigurator.configure(Client.class
            .getResource("/log4j.properties"));
    xdasLogger = Logger.getLogger("xdasLogger");
    logger = Logger.getLogger(Client.class);

    logger.info("normal");
    xdasLogger.info("xdas");
}

But my console output is as follows:

normal
2012-06-28 09:52:44,580 INFO  xdasLogger - xdas
xdas

Note that “xdas” is logged by both logger and xdasLogger, which is undesirable.

Does anyone know what changes I need to put into my log4j.properties to change the console output to the following?

normal
2012-06-28 09:52:44,580 INFO  xdasLogger - xdas

Solution (taken from accepted answer):

log4j.rootLogger=DEBUG, stdout
log4j.logger.org.apache=DEBUG, stdout
log4j.logger.xdasLogger=DEBUG, xdas

log4j.additivity.org.apache=false
log4j.additivity.xdasLogger=false

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%m%n

log4j.appender.xdas=org.apache.log4j.ConsoleAppender
log4j.appender.xdas.layout=org.apache.log4j.PatternLayout
log4j.appender.xdas.layout.ConversionPattern=%d %-5p %c - %m%n
  • 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-06T19:35:07+00:00Added an answer on June 6, 2026 at 7:35 pm

    Try setting the additivity of the loggers to false. This will avoid the propagation to the rootLogger.

    log4j.additivity.org.apache=false
    log4j.additivity.xdasLogger=false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have two different registrations/logins in the same application. One for
I have two different tables, lead and click. I would like to query MySQL
I have two different .Net projects, hosted on github. I would like to create
I would like to have a form that can submit to two different action
I have two images which i would like to compare and do different operations
I have two different views to the same database table and I would like
I have two different log flows which I would like to create in flume.
I would like to have two different displays of a node teaser depending on
I currently have two Backbone models: user and project. I would like to have
I have two classes Invoice and InvoiceItem. I would like Invoice to have a

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.