Re: [EXAMPLE] Easy RR loop debugging with Log4j
Re: [EXAMPLE] Easy RR loop debugging with Log4j
- Subject: Re: [EXAMPLE] Easy RR loop debugging with Log4j
- From: 時期 精霊 <email@hidden>
- Date: Thu, 7 Jul 2005 13:16:14 +0200
Hello,
I use:
PropertyConfigurator.
configure(WOApplication.application().
resourceManager().
pathURLForResourceNamed("log4j.properties",
"app", null));
// Setting up logging
NSLog.Log4JLogger debug =
new NSLog.Log4JLogger(Logger.getLogger("debug"),
NSLog.DebugLevelDetailed);
NSLog.Log4JLogger err =
new NSLog.Log4JLogger(Logger.getLogger("err"),
NSLog.DebugLevelCritical);
NSLog.Log4JLogger out =
new NSLog.Log4JLogger(Logger.getLogger("out"),
NSLog.DebugLevelInformational);
NSLog.setErr(err);
NSLog.setOut(out);
NSLog.setDebug(debug);
In application.java constructor
Then I still use
NSLog.out.appendln("OUT");
Regards
Kuon
On Jul 7, 2005, at 12:45 PM, Florijan Stamenkovic wrote:
Hi all.
I've been considering how to do make my logging life easier in
whatever direction. Came up with something. I don't know if many of
you figured out this approach (or maybe a better one), but for
those of you who did not:
A handy way to log RR loop (and just about anything else) in your
components using log4j and a superclass for your components...
Make a class that subclasses WOComponent and that will be a
superclass for your components. Make it look similar to this like
this:
//
// MyWOComponent.java
// Log4jTest2
//
// Created by Florijan Stamenkovic on 2005 07 7.
// Copyright (c) 2005 CNG Havaso. All rights reserved.
//
import com.webobjects.appserver.*;
//import logger
import org.apache.log4j.Logger;
public class MyWOComponent extends WOComponent
{
protected static Logger logger; //no other setup
needed as it is done with an external config file
public MyWOComponent(WOContext context)
{
super(context);
logger = Logger.getLogger(this.getClass()); //this will
enable your components to get a logger with *their* class being
passed as the arg,
}
public void awake() //example. override what you need
tracked
{
logger.debug("awake() called");
super.awake();
}
}
Then you automatically have a logger in all your components, and
that logger is assigned a fully qualified name of the concrete
class. No class importing (Logger i mean), or declaring of "logger"
or whatever needed... Just start logging. For me that alone is
beneficial enough to use this approach. Another handy thing could
be to define one's own importance level just for the RR loop. If
one does not want to have so many log statements even in DEBUG level.
A thing to note though is that when you set the logger up so that
the pattern includes a resolved class name (so, not the Logger
name, but the real class name determined at runtime), it will
resolve to the superclass name (MyWOComponent) for all logs written
there. Just so nobody gets confused by seeing the superclass log
awake()...
If you are a newbie who doesn't use log4j and is scared, well,
don't be. There are many good explanations and tutorials online,
and it will take you a day or two to get familiar, and three to get
handy with it. Download, and google "log4j tutorial".
DISCLAIMER: I made a small project to test this out and all works
fine. Didn't use it in any big thing yet. Will start doing so from
now on though.
Hope somebody will find this useful...
Cheers
Flor
p.s. - improvements?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40goyman.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden