tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From A Df <abbey_dragonfor...@yahoo.com>
Subject Re: Missing files for Apache and Log4J
Date Wed, 03 Aug 2011 10:17:08 GMT
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

  



Cheers,
A Df

From: Mark Eggers <its_toasted@yahoo.com>

To: Tomcat Users List <users@tomcat.apache.org>; A Df <abbey_dragonforest@yahoo.com>
>Sent: Friday, 29 July 2011, 19:04
>Subject: Re: Missing files for Apache and Log4J
>
>> From: A Df <abbey_dragonforest@yahoo.com>
>
>> Dear All:
>> 
>> I have created a Java web application and I want to have logging to ensure that 
>> the appropriate messages are stored in log files instead of to standard output. 
>> I found a link at http://tomcat.apache.org/tomcat-6.0-doc/logging.html and was 
>> following the instruction but I am unclear for these steps. My details are:
>> 
>>     * Apache Tomcat 6.0.26
>>     * Log 4j 1.2.16
>> 
>> The instructions specify
>> 
>>     * Build or download the additional logging components.
>> I am new to logging, so I am not sure what other extra are needed!
>> 
>>     * Replace $CATALINA_HOME/bin/tomcat-juli.jar with 
>> output/extras/tomcat-juli.jar.
>> Does this mean that I move the jar from that location and create the folders to 
>> put it in another location to have :C:\Program Files\Apache Software 
>> Foundation\Apache Tomcat 6.0.26\output\extras?
>> 
>> 
>>     * Place output/extras/tomcat-juli-adapters.jar in $CATALINA_HOME/lib.I 
>> cannot find the jar file in the Log4J download or Apache files so where is it 
>> located?
>> 
>> Is Log4J the best logging to use with a Java web app? Do you have any 
>> suggestions?
>> 
>> Thanks for your help,
>> A Df
>>
>
>Logging for a particular web application is different (or can be) than
>logging for Tomcat.
>
>What I normally do is leave Tomcat logging as is (or modify it for
>better cluster logging), and use logging-commons / log4j for web
>applications.
>
>Using logging-commons / log4j for a particular web application is
>pretty straightforward.
>
>1. Include commons-logging-1.1.1.jar and log4j-1.2.15.jar in your
>   application's WEB-INF/lib folder
>
>2. Create a logging.properties file or a log4j.xml file and place it
>   in the application's WEB-INF/class folder
>
>3. Add logging instructions to your classes
>
>By default logging-commons will use log4j, so no other special
>configuration is necessary.
>
>It's nice to use logging-commons, since this makes it easier to switch
>out logging from log4j to another package should you choose to.
>
>Since I know you use NetBeans, the following is NetBeans-specific:
>
>* Add the jars
>
>There are several ways to include third party jars in your
>project. The quick and dirty way is to do the following.
>
>1. Create a folder (call it libs) in your project
>2. Copy the jars into that folder
>3. Right-mouse click on the Libraries node in your project
>4. Select Add Jar/Folder
>5. Browse to where you copied the jar files
>6. Add them
>
>By default, those jars will now be packaged up in the WAR file and
>included in your application's WEB-INF/lib folder.
>
>For individual development this is probably OK. For a more robust
>environment, it might be nice to add the jars to version control, create a
>NetBeans library with the two jars, or even use Maven or Ivy to manage
>dependencies.
>
>* Create a properties file
>
>I actually prefer using the xml file, but there are several open
>issues with using custom DTDs or schemas when editing XML files with
>NetBeans. So, a properties file is easier to use.
>
>1. Navigate to your Source Packages -> <default package> node
>2. Right-mouse click and select New -> Other
>3. Find Properties File in the dialog box (it's under Other)
>4. Call it log4j (NetBeans adds the .properties)
>5. Edit away
>
>NetBeans will package up the file in WEB-INF/classes of your
>application, where it can be found by the log4j classes.
>
>Here's a quick example of a log4j.properties file:
>
>### direct messages to file simple.log ###
>log4j.appender.file=org.apache.log4j.FileAppender
>log4j.appender.file.File=${catalina.base}/logs/simple.log
>log4j.appender.file.layout=org.apache.log4j.PatternLayout
>log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
>
>### default logging level
>log4j.rootLogger=warn,file
>
>### for the simple application
>log4j.logger.simple.controller=info,file
>
>Read the documentation that comes with log4j on how to create
>log4j.properties files for more information. For example, change the
>log4j.logger definitions to fit your package names and desired level
>of logging.
>
>One thing of interest to note here is where the log gets written. I've
>used ${catalina.base}/logs as the directory for the log file. This
>will write simple.log in the same logging directory that Tomcat
>uses. This may or may not be what you want. Change the location as
>appropriate.
>
>
>. . . . just my two cents.
>/mde/
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>
>
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message