In a JSP, I am doing something simple like instantiating a class. Within the class constructor, I am merely logging a simple message. However, the log file never appears. I would expect to see it directly under the root of the application.
public class Person
private String lastName;
private String firstname;
private String ssn;
I found out that the xml configuration just doesn't work for a web application as it does for a regular Java application. Does anyone know why? I was able to get the logging to work when I replaced the xml configuration with a properties file.
src/main/resources is the default classpath resource directory for jar-based products, but src/main/webapp is better for WARs, since it models the entire non-generated subset of the WAR exactly as it will appear in the final product.
I have a goodly number of webapps that all use the WEB-INF/classes/log4j.xml file with no problems. In fact, my understanding is that the log4j.properties file doesn't support rolling logfiles, so I don't really have the option. Although being yelled at by the XML validator because the extensions aren't part of the stock DTD is not appreciated.
Sources may include data from the Fakebook Research Foundation with support from Gargle University
You're right. I was able to get the .xml configuration working.
Now I am looking to do something more sophisticated, please tell me if I should direct this to a different forum.
I only want to log application-specific messages, as in, only log.info or log.debug messages I have in code to this log file. Developer would look at this one. I would like the Tomcat-specific messages to go to catalina.out. A sysadmin would look at this one.
I would like to log hibernate messages to a competely separate log file. I would like to write out the hibernate sql to its own file. Maybe a DBA would look at this one.
I found out you can create multiple file appenders in one configuration file. I found a nice tutorial online -- http://ibswings.blogspot.com/2009/03/log4j-configuration-controlling-logging.html -- but for the most part, I figured this out on my own. One of the keys is additivity. By default, one file appender's messages will be appended to another file appender until it gets to root. If you set this to false then you are able to achieve distinct log messages for specific packages, such as within your application, or even hibernate SQL messages.
I'm including the configuration file I arrived at in case it is helpful to someone else:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">