Thanks Michael,
As I've implemented lot of logging in this component, I didn't feel like
wiping out all the nice logging just because of that circular dependency...
So I decided to ignore all settings from the log4j configuration file and
create a very specific Logger instance, programmatically.
Created a factory method which gives me a Logger instance, independent of
the root Logger, and has just one appender -- the ConsoleAppender.
*Instead of using *
private static Logger log = Logger.getLogger(MyClass.class);
*I use...*
private static Logger log = LoggingRescue.loggerFactory(MyClass.class);
*Fragment of the factory method...*
public static Logger loggerFactory(Class clazz)
{
/** The new Logger */
Logger log = null;
// Gets the logger for the class
log = Logger.getLogger(clazz);
log.removeAllAppenders();
...
/*
* Creates the console appender
*/
Layout consoleLayout = new PatternLayout(CONSOLE_LAYOUT);
Appender dspConsoleAppender = new ConsoleAppender(consoleLayout);
dspConsoleAppender.setName(CONSOLE_APPENDER_NAME);
log.addAppender(dspConsoleAppender);
log.setAdditivity(false);
log.setLevel(level);
...
return log;
}
Thanks,
Ivan Z. Alencar.
On Thu, Jul 17, 2008 at 6:12 AM, Michael Erskine <[EMAIL PROTECTED]>
wrote:
> Ivan Alencar [mailto:[EMAIL PROTECTED] wrote:
> > I've created a log4j appender (by extending AppenderSkeleton) which uses
> a
> > component that depends on log4j.
>
> If you can change the component then one technique I sometimes use is to
> pass in a Logger object which may be null. Or I suppose one could
> temporarily set the static logger for that class to null while I'm accessing
> it from an Appender. You can always programmatically disable the Logger for
> the component's class too with Logger.getLogger(whatever).setLevel()
>
> Typically I try to write components that don't rely on any particular
> logging framework at runtime - keep it optional.
>
> Regards,
> Michael Erskine.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
-----------------------------------------------------------------------------------
Ivan Zilotti Alencar
347-920-1226 (mobile)
212-514-7000 x5213 (work)
[EMAIL PROTECTED]
-----------------------------------------------------------------------------------