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 Marcel Gołuński <mg...@gmail.com> on 2007/01/18 13:15:52 UTC

Confirm successful reading of a conf file, check if loggers and appenders were instatntiated

Hello.
I made a little research before posting here. And i didn't find any 
interesting answers.
----------------------------------------
Major question:

(from log4j wiki's FAQ - not answered 
(http://wiki.apache.org/logging-log4j/FrequentlyAskedQuestions) )
"How can I get notified of errors during configuration and then handle them? 
For example, I want to log to a file but the directory does not exist yet. I 
want to catch that configuration error, create the directory and restart 
configuration."
(from wiki's requested features 
(http://wiki.apache.org/logging-log4j/Log4jRequestedFeatures) )
"PropertyConfigurator.configure() and doConfigure() methods should return 
some sort of status to know if the loaded properties are valid."

I'm using DOMConfigurator (configureAndWatch) to read a conf file for a 
jboss webapp (log4j1.2.8, checked 1.2.14 nothing changed). I want to know if 
the reading was successful. I think that there is no exeption thrown (even 
if file does not exist, not only on validation errors).
my questions:
- Is there any way to check if the conf file was read successfully (I may 
switch to properties configuration if it is supported there)
- Is there any way to check on configureAndWatch that file was actually 
reread and configuration changes were made. (For example to attach some 
actionPerformer to log4j configureAndWatch which will be triggered when 
reading occures.) (I suppose no)?
-----------------------------------------
Minor questions:
NOTE: I know that file appenders throw exeptions so it is easy there.

How can i determine that appenders and loggers were instantiated (created)?
my idea (not checked but i think working):
- logger
org.apache.log4j.LogManager
method: exist()

- appender (after attaching to a logger)
org.apache.log4j.Logger (exactly Category super class)
methods: isAttached(), getAppender(), getAllAppenders() (and Enumerate for 
the one im trying to check)

Is there any other way (easier, faster) to determine that loggers and 
appenders were created and attached succesfully?
Its a pity that log4j does not support exceptions, but i understand the 
"performance issue", and think that it is connected with the lack of 
exceptions.

Sorry for my English.

Best Wishes,
--
Marcel Golunski
Horus s.c. http://www.horus.com.pl 


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


Re: Confirm successful reading of a conf file, check if loggers and appenders were instatntiated

Posted by Curt Arnold <ca...@apache.org>.
On Jan 18, 2007, at 11:06 AM, James Stauffer wrote:

> Could the configure method be changed to return a boolean indicating
> sucess?  If someone detected that configuration failed, would log4j be
> in an undefined state so that configuring with another file might not
> produce the desired results?
>

In the strictxml project, I went out of my way to defer actually  
applying any configuration changes until processing was very likely  
to succeed, so that a parsing failure would leave the configuration  
unchanged.  The approach can fail if things that are only checked in  
the activateOptions method, but that was the best I could do without  
touching log4j itself.


> One way to detect config problems would be to run with -Dlog4j.debug
> and capture and parse System.out info produced by log4j.
>

That is useful for analysis, but isn't helpful if your program is  
trying to appropriately respond to a configuration problem.






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


Re: Confirm successful reading of a conf file, check if loggers and appenders were instatntiated

Posted by James Stauffer <st...@gmail.com>.
Could the configure method be changed to return a boolean indicating
sucess?  If someone detected that configuration failed, would log4j be
in an undefined state so that configuring with another file might not
produce the desired results?

One way to detect config problems would be to run with -Dlog4j.debug
and capture and parse System.out info produced by log4j.

On 1/18/07, Curt Arnold <ca...@apache.org> wrote:
>
> > On 1/18/07, Marcel Gołuński <mg...@gmail.com> wrote:
> >>
> >> Is there any other way (easier, faster) to determine that loggers and
> >> appenders were created and attached succesfully?
> >> Its a pity that log4j does not support exceptions, but i
> >> understand the
> >> "performance issue", and think that it is connected with the lack of
> >> exceptions.
>
>
> On Jan 18, 2007, at 9:39 AM, James Stauffer wrote:
>
> > I believe the reason that log4j configuration doesn't thow exceptions
> > is that normally logging isn't the core reason for the program and a
> > problem with logging shouldn't stop the program.
> >
> > If you look through the API I believe you will find methods to obtain
> > attached appenders so you could verify that way (but then your code
> > would have to know about your config).
> >
>
> My understanding is the lack of exceptions from the configurators was
> not motivated by performance concerns, but that a bad configuration
> file would not cause an otherwise working application to fail.
> Unfortunately, that design decision makes it difficult to
> programatically respond to configuration failures, like providing a
> backup configuration if the configuration file was missing.
>
> I did start an experimental project (search for strictxml) in the
> sandbox for new XML configurator that used a stricter syntax and
> provided more feedback on the processing of the configuration.
> However, that has been dormant for a while and probably will not see
> much addition effort until log4j 2.0 development starts whenever that
> is.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

Re: Confirm successful reading of a conf file, check if loggers and appenders were instatntiated

Posted by Curt Arnold <ca...@apache.org>.
> On 1/18/07, Marcel Gołuński <mg...@gmail.com> wrote:
>>
>> Is there any other way (easier, faster) to determine that loggers and
>> appenders were created and attached succesfully?
>> Its a pity that log4j does not support exceptions, but i  
>> understand the
>> "performance issue", and think that it is connected with the lack of
>> exceptions.


On Jan 18, 2007, at 9:39 AM, James Stauffer wrote:

> I believe the reason that log4j configuration doesn't thow exceptions
> is that normally logging isn't the core reason for the program and a
> problem with logging shouldn't stop the program.
>
> If you look through the API I believe you will find methods to obtain
> attached appenders so you could verify that way (but then your code
> would have to know about your config).
>

My understanding is the lack of exceptions from the configurators was  
not motivated by performance concerns, but that a bad configuration  
file would not cause an otherwise working application to fail.   
Unfortunately, that design decision makes it difficult to  
programatically respond to configuration failures, like providing a  
backup configuration if the configuration file was missing.

I did start an experimental project (search for strictxml) in the  
sandbox for new XML configurator that used a stricter syntax and  
provided more feedback on the processing of the configuration.   
However, that has been dormant for a while and probably will not see  
much addition effort until log4j 2.0 development starts whenever that  
is.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Confirm successful reading of a conf file, check if loggers and appenders were instatntiated

Posted by James Stauffer <st...@gmail.com>.
I believe the reason that log4j configuration doesn't thow exceptions
is that normally logging isn't the core reason for the program and a
problem with logging shouldn't stop the program.

If you look through the API I believe you will find methods to obtain
attached appenders so you could verify that way (but then your code
would have to know about your config).

On 1/18/07, Marcel Gołuński <mg...@gmail.com> wrote:
> Hello.
> I made a little research before posting here. And i didn't find any
> interesting answers.
> ----------------------------------------
> Major question:
>
> (from log4j wiki's FAQ - not answered
> (http://wiki.apache.org/logging-log4j/FrequentlyAskedQuestions) )
> "How can I get notified of errors during configuration and then handle them?
> For example, I want to log to a file but the directory does not exist yet. I
> want to catch that configuration error, create the directory and restart
> configuration."
> (from wiki's requested features
> (http://wiki.apache.org/logging-log4j/Log4jRequestedFeatures) )
> "PropertyConfigurator.configure() and doConfigure() methods should return
> some sort of status to know if the loaded properties are valid."
>
> I'm using DOMConfigurator (configureAndWatch) to read a conf file for a
> jboss webapp (log4j1.2.8, checked 1.2.14 nothing changed). I want to know if
> the reading was successful. I think that there is no exeption thrown (even
> if file does not exist, not only on validation errors).
> my questions:
> - Is there any way to check if the conf file was read successfully (I may
> switch to properties configuration if it is supported there)
> - Is there any way to check on configureAndWatch that file was actually
> reread and configuration changes were made. (For example to attach some
> actionPerformer to log4j configureAndWatch which will be triggered when
> reading occures.) (I suppose no)?
> -----------------------------------------
> Minor questions:
> NOTE: I know that file appenders throw exeptions so it is easy there.
>
> How can i determine that appenders and loggers were instantiated (created)?
> my idea (not checked but i think working):
> - logger
> org.apache.log4j.LogManager
> method: exist()
>
> - appender (after attaching to a logger)
> org.apache.log4j.Logger (exactly Category super class)
> methods: isAttached(), getAppender(), getAllAppenders() (and Enumerate for
> the one im trying to check)
>
> Is there any other way (easier, faster) to determine that loggers and
> appenders were created and attached succesfully?
> Its a pity that log4j does not support exceptions, but i understand the
> "performance issue", and think that it is connected with the lack of
> exceptions.
>
> Sorry for my English.
>
> Best Wishes,
> --
> Marcel Golunski
> Horus s.c. http://www.horus.com.pl
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/