You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4php-dev@logging.apache.org by Florian Semm <fl...@gmx.de> on 2011/11/12 20:26:05 UTC

trigger errors

i have ran some unit-tests with an incomplete xml-config. so how exact 
should be an configuration-error?

my appender config looks like this:

<appender name="default" />

there is no class attribute or layout option. should all this missing 
options trigger an error?


regards

florian


Re: trigger errors

Posted by Ivan Habunek <iv...@gmail.com>.
On 12 November 2011 20:26, Florian Semm <fl...@gmx.de> wrote:
> i have ran some unit-tests with an incomplete xml-config. so how exact
> should be an configuration-error?
>
> my appender config looks like this:
>
> <appender name="default" />
>
> there is no class attribute or layout option. should all this missing
> options trigger an error?

It should trigger an error (E_USER_WARNING)  and discard the
incomplete appender config. Do you get an error?

I will try it out a bit later. Getting some dinner now.

Regards,
Ivan

Re: trigger errors

Posted by Ivan Habunek <iv...@gmail.com>.
On 16 November 2011 08:27, Florian Semm <fl...@gmx.de> wrote:
> the coverage of the LoggerConfigurator is now at 90%. May I commit my tests?
>
> btw: there was no check if a the specified rendererClass/renderingClass
> exists. I fixed this in my tests too.

That's great. I don't think you have commit privileges so can you
please attach a patch to the configurator issue on JIRA [1] and I will
review and commit it.

[1] https://issues.apache.org/jira/browse/LOG4PHP-152

Regards,
Ivan

Re: trigger errors

Posted by Florian Semm <fl...@gmx.de>.
Am 14.11.2011 14:53, schrieb Ivan Habunek:
> On 13 November 2011 14:39, Florian Semm<fl...@gmx.de>  wrote:
>> the configurator and the adapters are good examples for separation of
>> concerns. :)
>>
>> the configurator-test only has tests for two error-cases, happy-path and
>> default-setup. i would like to write some addional testcases.
> That would be very welcome. I spent a lot of time on the code and
> tests, but tests are still in need of some attention.
>
> Regards,
> Ivan
the coverage of the LoggerConfigurator is now at 90%. May I commit my tests?

btw: there was no check if a the specified rendererClass/renderingClass 
exists. I fixed this in my tests too.


regards,

florian

Re: trigger errors

Posted by Ivan Habunek <iv...@gmail.com>.
On 13 November 2011 14:39, Florian Semm <fl...@gmx.de> wrote:
> the configurator and the adapters are good examples for separation of
> concerns. :)
>
> the configurator-test only has tests for two error-cases, happy-path and
> default-setup. i would like to write some addional testcases.

That would be very welcome. I spent a lot of time on the code and
tests, but tests are still in need of some attention.

Regards,
Ivan

Re: trigger errors

Posted by Florian Semm <fl...@gmx.de>.
Am 13.11.2011 10:54, schrieb Ivan Habunek:
> On 13 November 2011 09:25, Florian Semm<fl...@gmx.de>  wrote:
>> if we expect in a configuration an attribute like "name" or "class" and we
>> got nothing, we should call this trigger_error() function.
>>
>> i haven't seen that the LoggerConfigurator class validate the configuration.
>> The configurator still triggers errors if the config is incomplete.
>>
> You are right, of course. I have fixed this in trunk. There is warning
> triggered now if 'name' or 'class' attributes are missing in the
> appender node. Please update and retest.
>
> I have also tried to make error messages more meaningful where possible.
>
> If you're interested in how it works under the hood: there are now two
> stages in configuring from an XML file:
> 1. An Adapter object converts the XML file to a PHP array. The
> configuration values are not validated at this point, just the XML
> structure. For example, the missing 'name' node should have been
> reported here.
> 2. A Configurator object applies the configuration from the array to
> the log4php hierarchy. Everything is validated.
>
> It's the same for properties (ini) config files. They use a different
> Adapter, but the same Configurator.
>
> If you want to see what the translated configuration looks like, run:
> $conf = new LoggerConfigurator();
> print_r($conf->parse('log4php.xml'));
>
> Regards,
> Ivan
the configurator and the adapters are good examples for separation of 
concerns. :)

the configurator-test only has tests for two error-cases, happy-path and 
default-setup. i would like to write some addional testcases.


regards

florian

Re: trigger errors

Posted by Ivan Habunek <iv...@gmail.com>.
On 13 November 2011 09:25, Florian Semm <fl...@gmx.de> wrote:
> if we expect in a configuration an attribute like "name" or "class" and we
> got nothing, we should call this trigger_error() function.
>
> i haven't seen that the LoggerConfigurator class validate the configuration.
> The configurator still triggers errors if the config is incomplete.
>

You are right, of course. I have fixed this in trunk. There is warning
triggered now if 'name' or 'class' attributes are missing in the
appender node. Please update and retest.

I have also tried to make error messages more meaningful where possible.

If you're interested in how it works under the hood: there are now two
stages in configuring from an XML file:
1. An Adapter object converts the XML file to a PHP array. The
configuration values are not validated at this point, just the XML
structure. For example, the missing 'name' node should have been
reported here.
2. A Configurator object applies the configuration from the array to
the log4php hierarchy. Everything is validated.

It's the same for properties (ini) config files. They use a different
Adapter, but the same Configurator.

If you want to see what the translated configuration looks like, run:
$conf = new LoggerConfigurator();
print_r($conf->parse('log4php.xml'));

Regards,
Ivan

Re: trigger errors

Posted by Florian Semm <fl...@gmx.de>.
Am 12.11.2011 20:40, schrieb Christian Grobmeier:
> On Sat, Nov 12, 2011 at 8:36 PM, Ivan Habunek<iv...@gmail.com>  wrote:
>> On 12 November 2011 20:31, Christian Grobmeier<gr...@gmail.com>  wrote:
>>> Good question.
>>>
>>> In my world logging framework should never break an application. So...
>>> what exactly is an error? A console output? standard php logfile
>>> problem?
>> What I did in the new configurator is use trigger_error() with
>> E_USER_WARNING parameter. I think this is the standard PHP way to
>> report non-fatal errors.
>>
>> The user can handle the warnings as they see fit by implementing an
>> error handler. Also PHP will log the errors if an error log is
>> configured in the ini file.
> Read the docs - sounds good to me. Thanks.
>
> It is a pity that one looses the magic php powers if one doesn't use
> it every day :)
>
> Cheers
> Christian
>
>> Regards,
>> Ivan
>>
>
>
if we expect in a configuration an attribute like "name" or "class" and 
we got nothing, we should call this trigger_error() function.

i haven't seen that the LoggerConfigurator class validate the 
configuration. The configurator still triggers errors if the config is 
incomplete.

Re: trigger errors

Posted by Christian Grobmeier <gr...@gmail.com>.
On Sat, Nov 12, 2011 at 8:36 PM, Ivan Habunek <iv...@gmail.com> wrote:
> On 12 November 2011 20:31, Christian Grobmeier <gr...@gmail.com> wrote:
>> Good question.
>>
>> In my world logging framework should never break an application. So...
>> what exactly is an error? A console output? standard php logfile
>> problem?
>
> What I did in the new configurator is use trigger_error() with
> E_USER_WARNING parameter. I think this is the standard PHP way to
> report non-fatal errors.
>
> The user can handle the warnings as they see fit by implementing an
> error handler. Also PHP will log the errors if an error log is
> configured in the ini file.

Read the docs - sounds good to me. Thanks.

It is a pity that one looses the magic php powers if one doesn't use
it every day :)

Cheers
Christian

>
> Regards,
> Ivan
>



-- 
http://www.grobmeier.de

Re: trigger errors

Posted by Ivan Habunek <iv...@gmail.com>.
On 12 November 2011 20:31, Christian Grobmeier <gr...@gmail.com> wrote:
> Good question.
>
> In my world logging framework should never break an application. So...
> what exactly is an error? A console output? standard php logfile
> problem?

What I did in the new configurator is use trigger_error() with
E_USER_WARNING parameter. I think this is the standard PHP way to
report non-fatal errors.

The user can handle the warnings as they see fit by implementing an
error handler. Also PHP will log the errors if an error log is
configured in the ini file.

Regards,
Ivan

Re: trigger errors

Posted by Christian Grobmeier <gr...@gmail.com>.
On Sat, Nov 12, 2011 at 8:26 PM, Florian Semm <fl...@gmx.de> wrote:
> i have ran some unit-tests with an incomplete xml-config. so how exact
> should be an configuration-error?
>
> my appender config looks like this:
>
> <appender name="default" />
>
> there is no class attribute or layout option. should all this missing
> options trigger an error?

Good question.

In my world logging framework should never break an application. So...
what exactly is an error? A console output? standard php logfile
problem?

In the case above - currently I am unsure if we have a Schema for it.
This might help.

If we have a schema it might be sufficient to use:
http://www.php.net/manual/en/function.error-log.php

if an configuration error occurs.

Other opinions?

Cheers


>
>
> regards
>
> florian
>
>



-- 
http://www.grobmeier.de