[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: log4j examples ??
Chris Abney wrote:
>
> Does anyone know of any good examples that are available that illustrate
> basic usage of log4j.
> Those provided on the jakarta web pages (Trivial, Sort, SortAlgo) are not
> adiquate.
See that we start every method with a debug call. An implemention
rule is that every log call must contain 100% of the context to be
useful to an engineer to diagnos what's going on. So you
see that Value objects are dumping their state, stack traces etc
into the log message.
Also notice that debug calls are bounded by if() logic that skips
the wasteful creating of Strings when logging is disabled.
What's not shown in this example is the extensive method internal
logic debugging I typically do. The control file for log4j allows
you to configure logging on a per class, package, global level.
curt
public void ejbStore()
{
try
{
if (log.isDebugEnabled())
log.debug (PKGNAME + ".ejbStore(): enter, model=" +
this.accountDetails);
AccountDAO dao = getDAO();
dao.store(this.accountDetails);
}
catch (AccountDAOAppException se)
{
String msg = PKGNAME + "ejbStore() exe=" +
Debug.getStackTraceString(se);
log.error (msg);
throw new EJBException (se.getMessage());
}
catch (AccountDAOSysException acs)
{
String msg = PKGNAME + "ejbStore() exe=" +
Debug.getStackTraceString(acs);
log.error (msg);
throw new EJBException(acs.getMessage());
}