----- Original Message ----- > From: A Df <abbey_dragonfor...@yahoo.com> > To: Tomcat Users List <users@tomcat.apache.org>; Mark Eggers > <its_toas...@yahoo.com> > Cc: > Sent: Wednesday, August 3, 2011 3:17 AM > Subject: Re: Missing files for Apache and Log4J > > Hello Mates: > > I got the log file to work however, it does not have the date appended like > the > usual Tomcat Logs and does not creating a rolling daily file. I also wanted > to > have control over the usual logs that Tomcat produced so I combined your > instructions with those from this other website at > http://mrhaki.blogspot.com/2011/02/configure-log4j-on-tomcat.html to get the > content for the properties file. However, the problems are: > * the log files do not have the .log extension so they do not show up > file > type as text document instead just a type as file > > * the date is not being appended to the name > My code below is in the properties file in the Project default package folder > as > Mark Eggers suggested. I am not sure which property to modify to get the .log > extension and the date appended. > > > > #log4j.properties File > > log4j.rootLogger=INFO, CATALINA, CONSOLE > > #Tweet Tag Processor > log4j.logger.org.tweettagprocessorpackage=INFO, R > > # Define all the appenders > > # Configuration for a rolling log file. > log4j.appender.R=org.apache.log4j.DailyRollingFileAppender > # Edit the next line to point to your logs directory. > # The last part of the name is the log file name. > log4j.appender.R.file=${catalina.base}/logs/tagprocessor. > log4j.appender.R.encoding=UTF-8 > # Roll-over the log once per day > log4j.appender.R.DatePattern='.'yyyy-MM-dd'.log' > # Print the date in ISO 8601 format > log4j.appender.R.layout=org.apache.log4j.PatternLayout > log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p %c - %m%n > log4j.appender.R.append=true > > log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender > log4j.appender.CATALINA.file=${catalina.base}/logs/catalina-my. > log4j.appender.CATALINA.encoding=UTF-8 > # Roll-over the log once per day > log4j.appender.CATALINA.DatePattern='.'yyyy-MM-dd'.log' > log4j.appender.CATALINA.layout=org.apache.log4j.PatternLayout > log4j.appender.CATALINA.layout.ConversionPattern = %d [%t] %-5p %c - %m%n > log4j.appender.CATALINA.append=true > > log4j.appender.LOCALHOST=org.apache.log4j.DailyRollingFileAppender > log4j.appender.LOCALHOST.file=${catalina.base}/logs/localhost-my. > log4j.appender.LOCALHOST.encoding=UTF-8 > log4j.appender.LOCALHOST.DatePattern='.'yyyy-MM-dd'.log' > log4j.appender.LOCALHOSTlayout=org.apache.log4j.PatternLayout > log4j.appender.LOCALHOST.layout.ConversionPattern = %d [%t] %-5p %c - %m%n > log4j.appender.LOCALHOST.append=true > > log4j.appender.MANAGER=org.apache.log4j.DailyRollingFileAppender > log4j.appender.MANAGER.file=${catalina.base}/logs/manager-my. > log4j.appender.MANAGER.encoding=UTF-8 > log4j.appender.MANAGER.DatePattern='.'yyyy-MM-dd'.log' > log4j.appender.MANAGER.layout=org.apache.log4j.PatternLayout > log4j.appender.MANAGER.layout.ConversionPattern = %d [%t] %-5p %c - %m%n > log4j.appender.MANAGER.append=true > > log4j.appender.HOST-MANAGER=org.apache.log4j.DailyRollingFileAppender > log4j.appender.HOST-MANAGER.file=${catalina.base}/logs/host-manager-my. > log4j.appender.HOST-MANAGER.encoding=UTF-8 > log4j.appender.HOST-MANAGER.DatePattern='.'yyyy-MM-dd'.log' > log4j.appender.HOST-MANAGER.layout=org.apache.log4j.PatternLayout > log4j.appender.HOST-MANAGER.layout.ConversionPattern = %d [%t] %-5p %c - %m%n > log4j.appender.HOST-MANAGER.append=true > > log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender > log4j.appender.CONSOLE.encoding=UTF-8 > log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout > log4j.appender.CONSOLE.layout.ConversionPattern = %d [%t] %-5p %c - %m%n > > # Configure which loggers log to which appenders > log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=INFO, > > LOCALHOST > log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager]=\ > INFO, MANAGER > log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager]=\ > INFO, HOST-MANAGER
. . . . lots of stuff deleted . . . . In general: Do not mix application logging and Tomcat logging in the same properties file. Follow Chris's excellent comments and the instructions at: http://tomcat.apache.org/tomcat-6.0-doc/logging.html to enable Tomcat to use log4j. Unfortunately I didn't keep Chris's mail message, but you should be able to find it in the archives. Configure Tomcat logging in $CATALINA_BASE/conf/logging.properties and your application logging in $CATALINA_BASE/webapps/AppName/WEB-INF/classes/log4j.properties On file naming: From the javadoc for DailyRollingFileAppender: For example, if the File option is set to /foo/bar.log and the DatePattern set to '.'yyyy-MM-dd, on 2001-02-16 at midnight, the logging file /foo/bar.log will be copied to /foo/bar.log.2001-02-16 and logging for 2001-02-17 will continue in /foo/bar.log until it rolls over the next day. It doesn't appear that you will get the naming you desire until the log is copied over. On utility: Also from the Javadoc for DailyRollingFileAppender: DailyRollingFileAppender has been observed to exhibit synchronization issues and data loss. The log4j extras companion includes alternatives which should be considered for new deployments and which are discussed in the documentation for org.apache.log4j.rolling.RollingFileAppender. So, I'm thinking that you probably do not want to use the DailyRollingFileAppender in any case. Solutions: If you want your log files to look like this: bar.{current-date}.log bar.{yesterday}.log then it appears that you'll want to use RollingFileAppender and an appropriate policy from the log4j extras jar file. To do that for your web application, add apache-log4j-extras-1.1.jar to your project. Then you'll have to configure the RollingFileAppender and the required rollingPolicy in order to get the desired results. According to the log4j Wiki, RollingFileAppender and the required rollingPolicy can only be configured using an xml file (log4j.xml). Here's an application example: <!DOCTYPE log4j:configuration PUBLIC 'PUBLIC:-//log4j/log4j Configuration//EN' 'log4j.dtd'> <log4j:configuration> <appender name="SIMPLE" class="org.apache.log4j.rolling.RollingFileAppender"> <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy"> <param name="FileNamePattern" value="${catalina.base}/logs/simple.%d.log"/> </rollingPolicy> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %-5p %c.%M:%L - %m%n"/> </layout> </appender> <logger name="simple"> <level value="INFO"/> <appender-ref ref="SIMPLE"/> </logger> </log4j:configuration> This will log all classes in the package "simple" and below to $CATALINA_BASE/logs/simple.{date}.log. The file will be rotated nightly around midnight (according to the javadoc). You could try this type of configuration for Tomcat logging by placing apache-log4j-extras-1.1.jar in $CATALINA_HOME/lib. Then configure the appropriate loggers and appenders in $CATALINA_HOME/conf/log4j.xml. Unfortunately, according to the Tomcat documentation you may have trouble with a logger name that contains square brackets. In other words: <logger name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost]"> <level value="INFO"/> <appender-ref ref="LOCALHOST"/> </logger> may not be read properly by log4j. So I think you have some choices. In all cases, keep the logging configuration for Tomcat separate from your application. 1. Keep Tomcat logging via JULI (the default) and use log4j in your application You can use whatever application configuration you desire. If you do want to rotate logs, the javadoc for log4j suggests that you use the extras package. 2. Convert Tomcat to log4j following the Tomcat documentation and Chris's excellent comments. You will have to live with fact that the active logging files will not have a date in the name. Also, you'll need to quote the DatePattern in log4j.properties if you want your rotated file name to look like localhost.{date}.log. The Tomcat documentation has an example of this at: http://tomcat.apache.org/tomcat-6.0-doc/logging.html Again, you can configure your application to log however you want. 3. Try using the log4j extras package for Tomcat logging This will give you the file format that you want. It also has some nice properties like file compression on rotation. Unfortunately, you must use log4j.xml when using the extras package. This may present problems when trying to specify Tomcat logging names such as org.apache.catalina.core.ContainerBase.[Catalina].[localhost]. Again, this is (should be) completely separate from your application logging. . . . just my two cents. /mde/ --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org