Setting up Project Wonder Logging
Up to now I have stuck with standard
apache log4j setup and I have avoided even looking at ERXLogger and
related classes in Project Wonder. Using Project Wonder's logging which is part
of the ERExtensions framework has its advantages. You get to configure logging
on Project Wonder's classes which give an enormous amount of useful information
about what's going on and you also get a convenient configuration page for
configuring logging on the fly directly in your app while in development
mode....
This details how to set up Project Wonder
logging.Put a direct action
WOHyperLink somewhere in your app. I have it surrounded by a conditional
"isDevelopmentMode" so that it disappears in deployment. Name the link text as
"Log4j Config" or something like
that.
Set
bindings on the WOHyperLink:actionClass =
"ERXDirectAction"directActionName =
"log4j"In your project's Properties
file, put something along these lines. Study log4j property file format to learn
more.##########################################################################
ERXLogger
##########################################################################
Pattern codes:# %-5p : Priority DEBUG,
INFO, WARN, etc.# %d(ISO08601 : Date
and time# %t :
Thread# %c : Logger name (usually a
class name)# %m%n : Log message
arguments# Available levels are
DEBUG, INFO, WARN, ERROR,
FATAL//log4j appender and
formattinglog4j.rootLogger=INFO, A1,
A2log4j.loggerFactory=er.extensions.ERXLogger$Factory#
A1 is a
ConsoleAppenderlog4j.appender.A1=org.apache.log4j.ConsoleAppenderlog4j.appender.A1.layout=er.extensions.ERXPatternLayout#log4j.appender.A1.layout.ConversionPattern=%-5p
%d{HH:mm:ss} (%-20c:%L) %x
-%m%nlog4j.appender.A1.layout.ConversionPattern=%r
%-5p [%t] (%C, %M, %L) - %m%n%n#
A2 is a
DailyRollingFileAppenderlog4j.appender.A2=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.A2.file=/var/log/webobjects_apps/log4j_cheetah.loglog4j.appender.A2.datePattern='.'yyyy-MM-ddlog4j.appender.A2.append=truelog4j.appender.A2.layout=er.extensions.ERXPatternLayoutlog4j.appender.A2.layout.ConversionPattern=%-5p
%d{ISO8601} [%t] (%c) -
%m%n# Project Wonder
logger configuration#
---------------------------#log4j.logger.er=INFOer.extensions.ERXNSLogLog4jBridge=DEBUGlog4j.logger.er.eo.ERXGenericRecord=DEBUGlog4j.logger.er.validation.ERXEntityClassDescription=DEBUGlog4j.logger.er.default.ERXEntityClassDescription=DEBUG#
MyApp logger configuration#
---------------------------------------log4j.logger.WOComponentSubclass=DEBUGlog4j.logger.CustomersPage=DEBUGIf
you already had standard import org.apache.log4j statements and your own generic
static log creation statements in your class, they will automatically use
ERXLogger.Factory, so you don't have to change all your old log creation and
logging statements since ERXLogger uses log4j. If you followed my previous
instructions for log4j setup , then get rid of the
PropertyConfigurator statement in the Application class constructor since your
Application class should now be extending project wonder's ERXApplication which
takes care of logging config along with all the other startup
stuff.Neither do you now have to have
a specific statement in your application constructor to tell log4j where the
logging properties file is located since Project Wonder configures everything
from your WebObjects project Properties
file.Now when you launch your app, you
can use the log4j direct action to get to the logging config page built into
Project
Wonder
For
deployment, make sure the user appserver has privileges to write to the logs
folder, which is
'/var/log/webobjects_apps'
in the above example
Posted: Friday - June 17, 2005 at 04:09 PM