0

Hi i am working with product , i had problem in locating log file location at run time my file appender as follows , where in given location statically how can i edit this at run time.

<appender name="fileAppender" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="E:/log/SQLAppLog.log" />
    <param name="DatePattern" value="'_'yyyy-MM-dd'.log'" />
    <param name="Append" value="true" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern"
            value="%d{HH:mm:ss-SSS} | %t | %-5p | %C | %M | %L | %m%n" />
    </layout>
</appender>

Thank you in advance

2 Answers2

0

If you are configuring Log4j using log4j.xml file then you can't change your log location at run time since it gets loaded at start up... but if you are configuring log4j using java code then definitely you can change it at run time.

Pramod Kumar
  • 7,914
  • 5
  • 28
  • 37
0

Check the log4j api, it gives you handle to change the location of appender using the appender object.instead of using a static appender, you can also create an appender at run time using log4j apis.

sudmong
  • 2,036
  • 13
  • 12
  • Hi i have created log4j.propeties file and i called from my servlet , when i give System.out.println("Initializing log4j with: " + log4jProp);FileAppender appender = new FileAppender(); DailyRollingFileAppender appender1 = new DailyRollingFileAppender(); when i give values i am not getting log entry JDBCAppender appender2 = new JDBCAppender(); – MohanMaverick Jun 14 '12 at 09:13
  • Are you adding your appender to the root logger? See [Similar Question](http://stackoverflow.com/questions/8965946/configuring-log4j-loggers-programmatically). you may find lot more questions on stackoverflow and numerous links on google to do it. – sudmong Jun 14 '12 at 09:20