Posted comments (9)

Posted by Ejavam07 at November 7, 2008 04:16:11 UTC
Worked well for 1.2.15. Put the command line arg (-Dlog4j.debug=true) into the NetBeans IDE 6.1 and got the results through the output window while running in there.
Posted by Giri at May 19, 2009 16:20:51 UTC
Simply great example.Thank you very much.I appreciate your efforts.
Posted by Narayan at July 27, 2009 12:47:57 UTC
Nice, simple and easy

This is how tutorials ought to be
Posted by Amrutha at September 2, 2009 08:16:56 UTC
I got these errors while executing this tutorial program. kindly help.

D:\Java\jdk1.5.0_12\bin>java Log4jDemo

log4j:ERROR Could not instantiate class [org.apache.log4j.ConsoleAppender].
java.lang.ClassNotFoundException: org.apache.log4j.ConsoleAppender
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.apache.log4j.helpers.Loader.loadClass(Loader.java:179)
at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:320)
at org.apache.log4j.helpers.OptionConverter.instantiateByKey(OptionConverter.java:121)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:664)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:647)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:544)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:440)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:476)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)
at org.apache.log4j.Logger.getLogger(Logger.java:105)
at Log4jDemo.<clinit>(Log4jDemo.java:5)
log4j:ERROR Could not instantiate appender named "stdout".
log4j:WARN No appenders could be found for logger (Log4jDemo.class).
log4j:WARN Please initialize the log4j system properly.
Posted by Ryan at May 13, 2010 16:36:10 UTC
Date projDate = new Date(Long.parseLong(project.getTimeStamp()));
StringBuffer dateStr = new StringBuffer();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
dateStr = sdf.format(projDate, dateStr, new FieldPosition(0));
String logFileName = logsDir + File.separator + project.getName() + "_" + dateStr.toString() + ".log";
log.info("\n**************Log file for this run: " + logFileName + "\n**************\n");

Logger rootLogger = Logger.getRootLogger();
Enumeration appenders = rootLogger.getAllAppenders();
FileAppender fa = null;
while(appenders.hasMoreElements())
{
Appender currAppender = (Appender) appenders.nextElement();
if(currAppender instanceof FileAppender)
{
fa = (FileAppender) currAppender;
}
}
if(fa != null)
{
fa.setFile(logFileName);
fa.activateOptions();
}
else
{
log.info("No File Appender found");
}

Source:
http://cognitivecache.blogspot.com/2008/08/log4j-writing-to-dynamic-log-file-for.html
Posted by Kyrk at January 13, 2011 22:24:23 UTC
Thanks a lot, very helpful.
Posted by Marias at January 24, 2011 22:57:09 UTC
Where does one get the file: logging-log4j-1.2.9.zip mentioned in this tutorial?
Posted by Robert Lie at January 25, 2011 05:38:47 UTC
Marias,

logging-log4j-1.2.9.zip can be downloaded from:
http://archive.apache.org/dist/logging/log4j/
Posted by Mani at November 26, 2011 08:49:40 UTC
Very simple and much comfortable to understand

Thanks
Mani