You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Mohan.Radhakrishnan" <mo...@fss.co.in> on 2010/10/21 13:21:48 UTC

Extending Logger

The complete Log4J manual discourages us from extending Logger but we use the
recommended pattern
then 'repository' and 'getEffectiveLevel()' are inaccessible because they
are protected in Category.

      public void trace(Object message) {
        if (repository.isDisabled(Level.TRACE_INT)) {
          return;
        }

        if (Level.TRACE.isGreaterOrEqual(this.getEffectiveLevel())) {
          forcedLog(FQCN, Level.TRACE, message, null);
        }
      }

Can we extend Logger ?

-- 
View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30018462.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Extending Logger

Posted by "Mohan.Radhakrishnan" <mo...@fss.co.in>.
I don't have a way to put my custom logger in the log4j repository so that it
is used in place of the log4j Logger.
-- 
View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30111144.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Extending Logger

Posted by "Mohan.Radhakrishnan" <mo...@fss.co.in>.
I have wrapped log4j's Logger in a 'custom' logger. The custom logger is my
logger. The FQCN of my logger is set in the 'logger' element in the XML.

I have an extra parameter to set in my logger that is not in Log4j's logger.
So I think that I have to configure this when 

log4j calls  void selectAndConfigure(URL url, String clazz, LoggerRepository
hierarchy) {


-- 
View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30086102.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Extending Logger

Posted by Douglas E Wegscheid <Do...@whirlpool.com>.
I guess I don't understand the question: what are you wanting to do? 
programmatically set properties on a custom logger, or do it in xml? 

"custom" logger is a funny term: the configuration code handles 
distributed and customer-written loggers identically...

Douglas E Wegscheid
Lead Technical Analyst, Whirlpool Corporation
(269)-923-5278

"A wrong note played hesitatingly is a wrong note. A wrong note played 
with conviction is interpretation."





"Mohan.Radhakrishnan" <mo...@fss.co.in> 
10/29/2010 09:31 AM
Please respond to
"Log4J Users List" <lo...@logging.apache.org>


To
log4j-user@logging.apache.org
cc

Subject
Re: Extending Logger







Since extension of Logger is discouraged I wrap it.

I think the configuration can be set like this. 
<logger name="Test" class="com.fss.flux.log4jextension.SchedulerLogger">


Thanks,
Mohan

-- 
View this message in context: 
http://old.nabble.com/Extending-Logger-tp30018462p30085722.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org



Re: Extending Logger

Posted by "Mohan.Radhakrishnan" <mo...@fss.co.in>.
Since extension of Logger is discouraged I wrap it.

I think the configuration can be set like this. 
<logger name="Test" class="com.fss.flux.log4jextension.SchedulerLogger">


Thanks,
Mohan

-- 
View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30085722.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Extending Logger

Posted by Douglas E Wegscheid <Do...@whirlpool.com>.
can't you just cast the Logger to CustomLogger?

if (logger instanceof CustomLogger) {
 CustomLogger c = (CustomLogger) logger;
 c.customLoggersMethod();
}

Douglas E Wegscheid
Lead Technical Analyst, Whirlpool Corporation
(269)-923-5278

"A wrong note played hesitatingly is a wrong note. A wrong note played 
with conviction is interpretation."





"Mohan.Radhakrishnan" <mo...@fss.co.in> 
10/29/2010 08:28 AM
Please respond to
"Log4J Users List" <lo...@logging.apache.org>


To
log4j-user@logging.apache.org
cc

Subject
Re: Extending Logger







Solved this. 

Is there a way to get my custom logger that log4J has configured and set
some values using reflection ? The API does not seem to return the correct
type. It returns Logger always and not CustomLogger.
-- 
View this message in context: 
http://old.nabble.com/Extending-Logger-tp30018462p30085289.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org



Re: Extending Logger

Posted by "Mohan.Radhakrishnan" <mo...@fss.co.in>.
Solved this. 

Is there a way to get my custom logger that log4J has configured and set
some values using reflection ? The API does not seem to return the correct
type. It returns Logger always and not CustomLogger.
-- 
View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30085289.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Extending Logger

Posted by "Mohan.Radhakrishnan" <mo...@fss.co.in>.
I think I have done what was suggested but there is a catch.

I decided to go for a parallel log4j repository for more manageability but
retained the log4j Logger. I didn't extend it or wrap it. ( e.g ) JBoss uses
its own repository to take care of multiple web applications.

The problem is that since I am adding the appenders to log4j's Logger and
storing it in my own repository there is duplication. All the loggers and
appenders are in both repositories. I don't think there is will be a serious
performance issue because all the loggers are accessed from my repository
only but I want to disable log4j's repository but still use log4j's logger.

Does this make sense ?
-- 
View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30199446.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Extending Logger

Posted by Jacob Kjome <ho...@visi.com>.
I would tend to have a minimal log4j.xml containing basic configuration for 
the root logger, which I usually set to "WARN" to avoid being bombarded with 
annoying messages from libraries I don't care about.  However, there is no 
necessity to have a log4j.xml (or log4j.properties).  Log4j can be configured 
via config file or programmatically (or both), but if Log4j can't find any 
config file, it will say as much in System.err, which I generally try to 
avoid.

All the other stuff can be configured programmatically as Bender suggested.

Jake

On Tue, 2 Nov 2010 14:46:52 +0100
  Bender Heri <hb...@ergonomics.ch> wrote:
> I don't know. You have to try if the log4j.xml can be omitted. 
> Heri
> 
>> -----Original Message-----
>> From: Mohan.Radhakrishnan [mailto:mohanr@fss.co.in]
>> Sent: Tuesday, November 02, 2010 2:39 PM
>> To: log4j-user@logging.apache.org
>> Subject: RE: Extending Logger
>> 
>> 
>> Yes. I am responding to your suggestion.
>> 
>> The setup performance is not very important. The runtime performance though
>> is. If I setup everything programmatically log4j.xml is not at all needed ?
>> --
>> View this message in context: 
>>http://old.nabble.com/Extending-Logger-tp30018462p30113852.html
>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Extending Logger

Posted by Bender Heri <hb...@ergonomics.ch>.
I don't know. You have to try if the log4j.xml can be omitted. 
Heri

> -----Original Message-----
> From: Mohan.Radhakrishnan [mailto:mohanr@fss.co.in]
> Sent: Tuesday, November 02, 2010 2:39 PM
> To: log4j-user@logging.apache.org
> Subject: RE: Extending Logger
> 
> 
> Yes. I am responding to your suggestion.
> 
> The setup performance is not very important. The runtime performance though
> is. If I setup everything programmatically log4j.xml is not at all needed ?
> --
> View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30113852.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Extending Logger

Posted by "Mohan.Radhakrishnan" <mo...@fss.co.in>.
Yes. I am responding to your suggestion.

The setup performance is not very important. The runtime performance though
is. If I setup everything programmatically log4j.xml is not at all needed ?
-- 
View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30113852.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Extending Logger

Posted by Bender Heri <hb...@ergonomics.ch>.
I am confused. Do you respond to my suggestion? I suggested to set up everything Logger and Appender) programmatically, as it is defined in your own config file.
Which performance do you mean? The setup performance or the runtime, when the loggers are used? The latter is independantly of how you set up your logger univers, the former should not concern, or does it?
Heri

> -----Original Message-----
> From: Mohan.Radhakrishnan [mailto:mohanr@fss.co.in]
> Sent: Tuesday, November 02, 2010 2:26 PM
> To: log4j-user@logging.apache.org
> Subject: RE: Extending Logger
> 
> 
> So this is what I understand.
> 
> If I have too many appender sections in the XML then one appender for a
> logger is created by log4j.
> 
> Instead of that I can have one appender and a custom logger for each log
> file.
> 
> Both could be equivalent as far as performance is concerned. Am I right ?
> 
> --
> View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30113734.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Extending Logger

Posted by "Mohan.Radhakrishnan" <mo...@fss.co.in>.
So this is what I understand.

If I have too many appender sections in the XML then one appender for a
logger is created by log4j.

Instead of that I can have one appender and a custom logger for each log
file.

Both could be equivalent as far as performance is concerned. Am I right ?

-- 
View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30113734.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Extending Logger

Posted by Bender Heri <hb...@ergonomics.ch>.
If I understand you correctly:
You have many instances of your CustomLogger (as many as you want different log files), each wrapping a separate instance of Logger. The name of the file is configured in a file (I assume a pairing of logger names and file names?).
My suggestion: Do not extend Logger, but instantiate the Loggers programmatically and supply it with a FileAppender which is also instantiatted programmatically (based on your config file).
Heri
BTW: The extending of Logger is discouraged not because it would not work (well, some particular features wouldn't work anymore), but because one cannot imagine any reason why this would be necessary. The work of Log4j is done within the Appenders, Filters, Layouts, etc. The Logger class only provides an entry point for log statements in code.

> -----Original Message-----
> From: Mohan.Radhakrishnan [mailto:mohanr@fss.co.in]
> Sent: Tuesday, November 02, 2010 1:26 PM
> To: log4j-user@logging.apache.org
> Subject: RE: Extending Logger
> 
> 
> I wanted to associate the logger file with each Logger instead of the
> Appender. I have a setFile/getFile in the Logger that I plan to call using
> my custom Appender so that the log message is written to the file associated
> with the Logger.
> 
> Reasons :
> 
> 1. We have two many appender sections in the XML because there are too many
> log files.
> 2. I want to use my custom logger/appender and another xml file - not
> log4j.xml - to associate a logger with a file.
> 
> I am trying to parse and read the file name from my custom XML file and set
> it in my custom logger that log4j's repository has.
> --
> View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30113301.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Extending Logger

Posted by "Mohan.Radhakrishnan" <mo...@fss.co.in>.
I wanted to associate the logger file with each Logger instead of the
Appender. I have a setFile/getFile in the Logger that I plan to call using
my custom Appender so that the log message is written to the file associated
with the Logger.

Reasons :

1. We have two many appender sections in the XML because there are too many
log files.
2. I want to use my custom logger/appender and another xml file - not
log4j.xml - to associate a logger with a file.

I am trying to parse and read the file name from my custom XML file and set
it in my custom logger that log4j's repository has.
-- 
View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30113301.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Extending Logger

Posted by Bender Heri <hb...@ergonomics.ch>.
What is the reason you want extend the Logger? 
Heri

> -----Original Message-----
> From: Mohan.Radhakrishnan [mailto:mohanr@fss.co.in]
> Sent: Thursday, October 21, 2010 1:22 PM
> To: log4j-user@logging.apache.org
> Subject: Extending Logger
> 
> 
> The complete Log4J manual discourages us from extending Logger but we use the
> recommended pattern
> then 'repository' and 'getEffectiveLevel()' are inaccessible because they
> are protected in Category.
> 
>       public void trace(Object message) {
>         if (repository.isDisabled(Level.TRACE_INT)) {
>           return;
>         }
> 
>         if (Level.TRACE.isGreaterOrEqual(this.getEffectiveLevel())) {
>           forcedLog(FQCN, Level.TRACE, message, null);
>         }
>       }
> 
> Can we extend Logger ?
> 
> --
> View this message in context: http://old.nabble.com/Extending-Logger-tp30018462p30018462.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org