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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:43:51+00:00 2026-05-15T14:43:51+00:00

I use log4j in my project and wanted to use FallbackErrorHandler for Backup-Reasons. So,

  • 0

I use log4j in my project and wanted to use FallbackErrorHandler for Backup-Reasons. So, when I want to implement a FallbackErrorHandler, you have to use the DOMConfigurator and that for a XML-Configurationfile.

But now, my customer doesn´t really like XML and looking for a way, he can configure the Logging-behaviour himself, I got the idea to load the basic configuration with the help of java-properties und instantiating the higher Appender or ErrorHandler with Java-Code, which I could configure with parameters.

The configuration of the ErrorHandler worked so far, the log4j-debug showing everythings correct, but I ran into a problem I could not solve until yet. My FallbackErrorHandler starts logging to the backupAppender already at the start of the programm, not when a standard appender failed. I couldn´t figure out what I´ve done wrong, I can post the code of the properties and the java-code if somebody wants to look at it, but at first, I wanted to ask, whether somebody ran into the same problem or has any experiences with configuring log4j within Java?

  • 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-15T14:43:51+00:00Added an answer on May 15, 2026 at 2:43 pm

    After weeks of trying I now finally found a solution. The key event was the discovery, that also the PropertyConfigurator has a class for ErrorHandler, although Geki wrote, that there is no possibility to configure a ErrorHandler with the PropertyConfigurator. So I went on trying.

    Now I could simply combine the basic declaration in the log4j.properties with the linking of Logger, Appender and ErrorHandler in JavaCode.
    So following stands in my Properties:

    log4j.appender.ServerAppender=org.apache.log4j.FileAppender
    log4j.appender.ServerAppender.layout=org.apache.log4j.PatternLayout
    log4j.appender.ServerAppender.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} [%t] %-5p %F - %m%n 
    log4j.appender.ServerAppender.file=logs/ServerLog.txt
    log4j.appender.ServerAppender.threshold=DEBUG
    
    log4j.logger.com.foo.server=TRACE, ServerAppender
    
    log4j.appender.ServerAppender.errorhandler=org.apache.log4j.varia.FallbackErrorHandler
    log4j.appender.ServerAppender.errorhandler.logger-ref=com.foo.server
    log4j.appender.ServerAppender.errorhandler.appender-ref=FallbackServerAppender
    
    log4j.appender.FallbackServerAppender=org.apache.log4j.FileAppender
    log4j.appender.FallbackServerAppender.layout=org.apache.log4j.PatternLayout
    log4j.appender.FallbackServerAppender.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} [%t] %-5p %F - %m%n 
    log4j.appender.FallbackServerAppender.file=C:/Temp/Test/fallbackServerLog.txt
    
    log4j.logger.com.foo.error=DEBUG,FallbackServerAppender
    

    While com.foo.server is a part of my package hierarchy, com.foo.error is only a placeholder, so I can call it within Java-Code. That will look like this.

    PropertyConfigurator.configure(LOG4JCONFIG);
    FallbackErrorHandler fbeh=(FallbackErrorHandler)LogManager.getLogger("com.foo.server").getAppender("ServerAppender").getErrorHandler();
    fbeh.setLogger(LogManager.getLogger("com.foo.server"));
    fbeh.setAppender(LogManager.getLogger("com.foo.server").getAppender("ServerAppender"));         
    fbeh.setBackupAppender(LogManager.getLogger("com.foo.error").getAppender("FallbackServerAppender"));
    

    A known problem, the fallbackErrorHandler doesn´t reset when the Appender is on again, could be solved by restarting the configure()-method in or after situations, where normally the normal Appender can´t log.

    Hope it could help somebody 🙂

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

Sidebar

Related Questions

I have a project that use both dependencies independently: BoneCP and Hibernate. But thanks
I have been told to use log4j for my logging project,but before using log4j,
I have a simple log4j.property file and a simple program that use log4j. But
I have a java main application, and I want to use log4j. I don't
How do I implement and use log4j/logback in my JSP/Servlet project? What is the
I would like to use log4j.net in my windows forms project. However I have
I have a large web project that uses log4j directly, together with many 3rd-party
I have a following question. We use log4j in our two projects, that are
I have a project using common-logging and log4j , I want to change to
I want to use log4j in my jsp s and servlets. I read apache

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.