sahrom
asked on
struts app and adding logging to it using common or jdk14looger - syntax for FileHandler
I would like to add logging to a struts application - but not sure how to
I have common logger set up and it is working but only writes to the console
how in the properties file would I specify an file to put it out to
I ran across this:
Handler fh = new FileHandler("%t/wombat.log ");
Logger.getLogger("").addHa ndler(fh);
but I would like it in the properites file
org.apache.commons.logging .simplelog .????
thank you!!
also what goes in the commons-logger.properties and what should go in the simplelog.properties
I have common logger set up and it is working but only writes to the console
how in the properties file would I specify an file to put it out to
I ran across this:
Handler fh = new FileHandler("%t/wombat.log
Logger.getLogger("").addHa
but I would like it in the properites file
org.apache.commons.logging
thank you!!
also what goes in the commons-logger.properties and what should go in the simplelog.properties
ASKER
Thanks very much for you reply. There is so much more documentation on Log4J, that I would have tried this one to begin with , but I was told they had tried and there was a problem somewhere. They are using JBoss
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Log4J http://logging.apache.org/log4j/docs/ requires you to download the jars and place a properties file in the WEB-INF lib.
here's and example of how to configure a properties file
log4j.log
-------------
<!--
Log4J Configuration Quick Reference:
==========================
Priority order is DEBUG < INFO < WARN < ERROR < FATAL
PatternLayout conversion characters:
%c Category of the logging event
%C Fully qualified class name of the caller
%d Date of the logging event (example: %d{HH:mm:ss,SSS} )
%F File name where the logging request was issued (caution: extremely slow
)
%l Location information of the caller (caution: extremely slow)
%L Line number from where the logging request was issued (caution: extreme
ly slow)
%m Application-supplied message
%M Method name from where the logging request was issued (caution: extreme
ly slow)
%n Line separator
%p Priority of the logging event
%r Number of milliseconds since the start of the application
%t Name of the thread that generated the logging event
%x Nested diagnotic context associated with the thread
%% A single percent sign
Format modifiers examples:
%20c Left pad with spaces if category is less than 20 characters long
%-20c Right pad with spaces if category is less than 20 characters long
%.30c Truncate from the beginning if category is more than 30 chars long
%20.30c Left pad 20 chars + truncate from beginning if more than 30 chars
%-20.30c Right pad 20 chars + truncate from beginning if more than 30 chars
Examples: "%r [%t] %-5p %c %x - %m\n"
"%-6r [%15.15t] %-5p %30.30c %x - %m\n"
-->
#level is debug and goes to stdout and R which we will specify later
log4j.rootLogger=debug, stdout, R
log4j.appender.stdout=org.
log4j.appender.stdout.layo
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layo
log4j.appender.R=org.apach
og4j.appender.R.DatePatter
log4j.appender.R.File=./lo
# log4j.appender.R.MaxFileSi
# Keep one backup file
# log4j.appender.R.MaxBackup
log4j.appender.R.layout=or
log4j.appender.R.layout.Co
calling the log in a struts action
-------------------
//normal imports
// Jakarta
import org.apache.log4j.Logger;
public class MyAction extends Action {
private static final Logger _LOGGER = Logger.getLogger( MyAction .class.getName() );
public ActionForward execute(
final ActionMapping pMapping,
final ActionForm pForm,
final HttpServletRequest pRequest,
final HttpServletResponse pResponse)
throws Exception {
_LOGGER.info(" action has started" ); //make logger call at info level
//blah blah return an actionforward
} // execute