Note that there are some explanatory texts on larger screens.

plurals
  1. POlog4j setting log file name @ runtime not working
    primarykey
    data
    text
    <p>We have a requirement in the application that the log file created shoud have a different name every time it executes (based on functionality + the current thread). I have seen the questions already posted in SO and tried to use the same method, but it is not working.</p> <p>All the log statements are getting logged in "xyz.log" (specified in the log4j.properties). Only "org.apache.log4j.PatternLayout" gets logged in abc.log (specified in the program). Any pointers to solve this will be very helpful. </p> <p><strong>log4j.properties</strong></p> <pre><code>log4j.rootLogger=DEBUG, MyLogger log4j.appender.MyLogger=org.apache.log4j.FileAppender log4j.appender.MyLogger.layout=org.apache.log4j.PatternLayout log4j.appender.MyLogger = org.apache.log4j.DailyRollingFileAppender log4j.additivity = false log4j.appender.MyLogger.File=xyz.log log4j.appender.MyLogger.MaxFileSize = 5MB log4j.appender.MyLogger.MaxBackupIndex = 20 # Pattern to output the caller's file name and line number. log4j.appender.MyLogger.layout.ConversionPattern=%d %5p [%t](%c:%L) - %m%n </code></pre> <p><strong>Java code</strong></p> <pre><code> logger = Logger.getLogger(MyLoggerUtil.class); Layout layout = new PatternLayout("org.apache.log4j.PatternLayout"); logger.removeAllAppenders(); FileAppender appender = null; try { appender = new FileAppender(layout, "abc.log", false); } catch (IOException e) { e.printStackTrace(); } logger.addAppender(appender); logger.setLevel((Level) Level.DEBUG); logger.debug("This is a debug test"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload