Best Practice on Configuring Log4j Properties Path

前端 未结 2 972
春和景丽
春和景丽 2020-12-16 06:40

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

相关标签:
2条回答
  • 2020-12-16 07:04

    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 讨论(0)
  • 2020-12-16 07:07

    When searching for items on the classpath the first instance of file with a matching name is used. So add your .jar to the front.

    set CLASSPATH=myfile.jar;%CLASSPATH%
    
    0 讨论(0)
提交回复
热议问题