[Waste-first] [Jhs-mail] JhsCommon Project and LOGGING!!!!!!!

Kirkpatrick, Ivan Ivan.Kirkpatrick@dep.state.fl.us
Fri, 18 Feb 2005 13:49:11 -0500


With considerable help from Danny O'Donnell I managed to clean up the
PhoneNumber class.  It is quite different now and much improved over =
what we
reviewed in class.

I would like everyone with the help of their project leads to make an =
effort
to implement logging and to take a shot at  adding some Junit tests into
their projects.  At the very least please install and configure your =
favorite
IDE with the JUnit plugin and try it out.  Let me know if you cannot get =
this
working correctly and I will help out.  Feel free to take a look at the
jhs-common project's JUnit tests and all other reports there as well at
http://epic51/jhs-common

Log4j documentation can be found at =
http://logging.apache.org/log4j/docs/

The basics for logging are as follows.  Include the log4j.jar in your
project's dependencies section of the project.xml and in your local IDE. =
You
will also need to include a log4j.properties file in the top level of =
your
web application or somewhere along the classpath.  I have inlined a =
useful
log4j.properties file.  Note that the correct location of the file is =
not
readily apparent if you are running your app in JDev using the embedded =
oc4j.

In the main servlet or startup servlet you will need to import

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

create the top level Logger logger in your main servlet class like this:

static { Logger logger =3D
org.apache.log4j.Logger.getLogger(YOUR_CLASS_NAME_HERE.class);
        PropertyConfigurator.configure("log4j.properties");
}

log statements using:

    logger.info("An interesting informational event has occurred."); or

    logger.warn("warning message!"); or

    logger.error("an error has occurred" + errorDetails); or

    logger.fatal("A really bad thing happened on the way here...");

    logger.debug("This output is for debugging");

The use of logging in your other classes does not require a new
PropertyConfigurator because all other loggers will be children of the =
first
or main logger.  All you have to do is create another logger in your new
class as:
Logger logger =3D
org.apache.log4j.Logger.getLogger(YOUR_CLASS_NAME_HERE.class);
=20
This avoids the overhead of additional configurations.

Logging is quite flexible in that we can suppress log messages at =
runtime by
adjusting the log4j.properties file.  The log4j.properties file =
configures a
Rolling file appender so that log files will only be 100Kb long and it =
will
shift them until a total of ten exist, then discard the oldest file.

The output should be configured in your log4j.properties files as =
GrpProj.log
where GrpProj is the acronym for your project.  Later we will direct =
logs to
a special logging partition and make them available via the web server =
so
they will be easily reviewed.  We will eventually implement a script =
that
scans the logs for your project and looks for messages that indicate an =
error
or Exception has occurred.  Use logging liberally, the overhead is on =
the
order of milliseconds so it is not a problem.  Good logging will go a =
long
way toward troubleshooting your applications.  Anyone or any project =
having
troubles getting log4j working properly should send a note to me, Mike =
Maheu
or Danny O'Donnell for assistance.  Please try it yourself first and =
consult
the online references. =20

A sample log4j.properties file

log4j.rootLogger=3Ddebug, stdout, R

log4j.appender.stdout=3Dorg.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=3Dorg.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=3D%5p [%t] (%F:%L) - %m%n

log4j.appender.R=3Dorg.apache.log4j.RollingFileAppender
# *********************************************************************
log4j.appender.R.File=3DGrpProj.log
#**********************************************************************

log4j.appender.R.MaxFileSize=3D100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=3D1

log4j.appender.R.layout=3Dorg.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=3D%p %t %c - %m%n=20


_______________________________________________
Jhs-mail mailing list
Jhs-mail@lists.dep.state.fl.us
http://lists.dep.state.fl.us/cgi-bin/mailman/listinfo/jhs-mail