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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:16:17+00:00 2026-05-13T13:16:17+00:00

Here’s what I’m trying to do: I want 2 log files: The first logs

  • 0

Here’s what I’m trying to do: I want 2 log files: The first logs INFO level and up for all parts of the applications but also logs DEBUG and up for some packages. The second only logs ERROR and up across all packages. I’m sure this is probably trivial but I can’t quite figure it out. Here is the configuration file I am currently using:

log4j.rootLogger=INFO,console,R

#console appender
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern = %t %-5p %c{2} - %m%n

#file appender
log4j.appender.R = org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.DatePattern = '.'yyyy-MM-dd
log4j.appender.R.File = log/log.txt
log4j.appender.R.layout = org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern = [%d{ISO8601}]%5p%6.6r[%t]%x(%F:%L) - %m%n

#Specific log levels
log4j.category.com.mypackage1=DEBUG
log4j.category.com.mypackage2=DEBUG

This doesn’t have the error log part, obviously. My basic idea was to add another appender and set its log level to ERROR but the categories seem to override it and and their info in as well, which is not what I want. The reason they are there is because the other packages dump alot of information that we don’t need when set to debug and this is how we are getting around it. I’m thinking there may be a better overall approach to this but this is my first log4j config file ever.

UPDATE: A co-worker suggested using 2 loggers as is mentioned in the post that kdgregory linked to in his comment (Different log4j layout for debug and error?). People there seemed to think it was a bad idea but no one ever explained why. It does seem a bit hacky but it does what we need. What are the main reasons to not use that method (other than having to maintain 2 different loggers)?

  • 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-13T13:16:17+00:00Added an answer on May 13, 2026 at 1:16 pm

    Here is what I eventually came up with that did the trick:

    log4j.rootLogger=INFO,console,stdLog,errorLog
    
    #console appender
    log4j.appender.console = org.apache.log4j.ConsoleAppender
    log4j.appender.console.layout = org.apache.log4j.PatternLayout
    log4j.appender.console.layout.ConversionPattern = %t %-5p %c{2} - %m%n
    
    #file appender
    log4j.appender.stdLog=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.stdLog.DatePattern = '.'yyyy-MM-dd
    log4j.appender.stdLog.File = log/log.txt
    log4j.appender.stdLog.layout = org.apache.log4j.PatternLayout
    log4j.appender.stdLog.layout.ConversionPattern = [%d{ISO8601}]%5p%6.6r[%t]%x(%F:%L) - %m%n
    
    #file appender
    log4j.appender.errorLog = org.apache.log4j.DailyRollingFileAppender
    log4j.appender.errorLog.DatePattern = '.'yyyy-MM-dd
    log4j.appender.errorLog.File = log/errorlog.txt
    log4j.appender.errorLog.layout = org.apache.log4j.PatternLayout
    log4j.appender.errorLog.layout.ConversionPattern = [%d{ISO8601}]%5p%6.6r[%t]%x(%F:%L) - %m%n
    log4j.appender.errorLog.Threshold=ERROR
    
    #Specific log levels
    log4j.category.com.mypackage1=DEBUG
    log4j.category.com.mypackage2=DEBUG
    

    This makes 2 logs, one which logs everything at Warn or above plus at DEBUG or above on the specified packages for the standard log and at ERROR and above only across all packages to the error log.

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

Sidebar

Related Questions

here is a debatable question which i want to achieve not sure how .
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the css: #content ul { font-size: 12px; } I am trying this:
Here is what I am trying to achieve in PHP: I have this string:
Here's what I'm trying to do... It's quite simple and obviously there must be
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here's the context: I have a file (or stream), and I want to process
Here's the thing: I want to add some images programmatically. The images should have
Here is my project Here I want to insert something into my database. I
Here is my problem...I have a page that loads a list of clients and

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.