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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:06:17+00:00 2026-05-19T16:06:17+00:00

I am using Log4j in my applications. log4j.properties is placed in a Jar which

  • 0

I am using Log4j in my applications. log4j.properties is placed in a Jar which is in classpath. This configuration file is being used and works fine most of the times.

But sometimes, the logging statements that are getting generated are not as per the configuration file.

My understanding is, this is because the properties file is fetched from the class path. Whatever first properties file is, is fetched and used by log4j. Thus sometimes we get the logging statements different from what is configured in properties file.

In case, the above reason is true, then I think, we need to specify the configuration file specifically by one of the following ways:

  1. Specify using System Properties :
    -Dlog4j.configuration=log4j.properties
  2. Initializing Log4jInit servlet.

Please suggest which could be the better approach.

  • 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-19T16:06:18+00:00Added an answer on May 19, 2026 at 4:06 pm

    In my application I am using ${user.home} dir to store log4j.properties and using ant we are reading it. it will be platform independent. also you can pass one with build in classpath but reading from ${user.home} is better approach, You or any non technical person can easily access it.

    also you can use

    Dynamic Log File Location

    Many people complain that Log4j forces you to hard-code the location where your logs will be kept. Actually, it is possible to dynamically choose the log-file location, especially if you use the ${log.dir} property substitution technique above. Here’s how:

    String dynamicLog = // log directory somehow chosen...
    Properties p = new Properties( Config.ETC + "/log4j.properties" );
    p.put( "log.dir", dynamicLog ); // overwrite "log.dir"
    PropertyConfigurator.configure( p );
    

    Also See

    • Effective logging practices ease enterprise development
    • Log4j Best practices
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My procedure for using log4j is this: put a .properties file somewhere in a
Using the xml configuration of log4cxx (which is identical in configuration to log4j). I
I have configured a project with Log4j. I have configured log4j using log4.properties file.
I have an application for which log4j logging is configured in a log4j.properties file.
I've just started using Log4J for the first time. I created a log4j.properties file
So we have our J2EE application using Log4j like this public class CustomerController {
I am used to using Tomcat/Log4J for my logging. My current project is deployed
I want to maintain two Log Files in my web-application using apache Log4j.jar: 1)
I'm using Log4j in a application in which I also use Axis2 and Jetty
I'm building an executable jar-with-dependencies using maven. My application uses log4j and there's an

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.