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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:14:11+00:00 2026-05-28T02:14:11+00:00

I have two loggers. One that appends to a file, and another that is

  • 0

I have two loggers. One that appends to a file, and another that is an smtp logger. There is a class (MyClass below) that is logging error messages that I would like to log to the file appender ONLY. Can this be done?

I tried adding this with no luck.

log4j.logger.com.test.MyClass=OFF, email_logger

Here is my log4j.properties.

log4j.logger.com.test=INFO, file_logger, email_logger
log4j.logger.com.test.MyClass=OFF, email_logger

log4j.additivity.com.test=false

log4j.appender.file_logger=org.apache.log4j.RollingFileAppender
log4j.appender.file_logger.file=/path/to/file.log
log4j.appender.file_logger.MaxFileSize=5MB
log4j.appender.file_logger.threshold=INFO
log4j.appender.file_logger.MaxBackupIndex=5
log4j.appender.file_logger.layout=org.apache.log4j.PatternLayout
log4j.appender.file_logger.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n

log4j.appender.email_logger=org.apache.log4j.net.SMTPAppender
log4j.appender.email_logger.threshold=ERROR
log4j.appender.email_logger.SMTPHost=mtahost
log4j.appender.email_logger.BufferSize=512
log4j.appender.email_logger.subject=System Error
log4j.appender.email_logger.from=test@test.com
log4j.appender.email_logger.to=someone@test.com
log4j.appender.email_logger.layout=org.apache.log4j.PatternLayout
log4j.appender.email_logger.layout.ConversionPattern=%d [%t] %-5p %c{1} - %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-05-28T02:14:12+00:00Added an answer on May 28, 2026 at 2:14 am

    I figured it out. I was thinking about it incorrectly. With the configuration above, I was actually turning off all logging on MyClass altogether. What I wanted to do was remove the email appender from MyClass and leave the file appender. I also needed to additivity to false on MyClass so that the same messages is not picked up by the base (log4j.logger.com.test) logger.

    I removed this line:

    log4j.logger.com.test.MyClass=OFF, email_logger
    

    And added these lines:

    log4j.logger.com.test.MyClass=INFO, file_logger
    log4j.additivity.com.test.MyClass=false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes, and want to include a static instance of one class
I have implement a log4j.xml file having two loggers. Both EventLogger and ErrorLogger logged
So, I have two threads. Thread one manages the client connections. (There is only
I have two applications written in Java that communicate with each other using XML
I have two identical tables and need to copy rows from table to another.
I have two threads, one needs to poll a bunch of separate static resources
I have two spreadsheets... when one gets modified in a certain way I want
I have two webapplication, one is a simple authenticationsite which can authenticate the logged
Given two appenders: A1, A2 and multiple loggers one of which is L1 Is
My Application is using logging in two manner....1) programatic 2) log4j.xml I have 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.