You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Felix Knecht <fe...@otego.com> on 2010/06/03 23:15:55 UTC

Exception Logging

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

We have a lot of following constructs:

log.error( I18n.err( I18n.ERR_04007 ) );
throw new DecoderException( I18n.err( I18n.ERR_04007 ) );

What about logging the exception within the exception itself like

public DecoderException(String message)
{
    super( message );
    log.error( message );
}


This will avoid having log.error all over the place and the translation
must be done only once instead of twice like above.

Regards
Felix
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwIG4oACgkQ2lZVCB08qHEb9wCgySj2lTnUNX6eob7BZZKGS/tQ
YFcAoI/BA8jtyHBFEKwQ3pYJtYOGLktV
=YeB5
-----END PGP SIGNATURE-----

Re: Exception Logging

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Jun 4, 2010, at 6:58 AM, Emmanuel Lecharny wrote:

>> No worries.  :) Why do they all have numbers in them?
>>   
> 
> Grep is your friend when you have accurate elements to work on :) Numbers are less versatile than textual descriptions.
> 
> /me remember a 5 days debugging session on a production serveur generating 5Gb of logs a day, using grep to grab the errors I was looking for...

On Jun 4, 2010, at 6:57 AM, Felix Knecht wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> 
>> No worries.  :) Why do they all have numbers in them?
> 
> Because there's also a request to build a knowledgebase [1]. It's easier
> having numbers to lookup something in a knowledgebase than having a text
> which may occur multiple times and for different exceptions.

All good reasons.


Regards,
Alan


Re: Exception Logging

Posted by Emmanuel Lecharny <el...@gmail.com>.
On 6/4/10 3:44 PM, Alan D. Cabrera wrote:
> On Jun 4, 2010, at 6:13 AM, Emmanuel Lecharny wrote:
>
>    
>> On 6/4/10 2:55 PM, Alan D. Cabrera wrote:
>>      
>>> Finally, what the heck is ERR_04007? :)  I thought there already was a discussion and community consensus about how there is little to negative value in using numbers as error messages.  Maybe I missed the conversation where this opinion was reversed.  If so, ignore this bit.  :)
>>>
>>>        
>> No, nobody missed this valid concern. We are just modifying them one by one when fixing issues using those error code :
>>
>>     ERR_02014_UNSUPPORTED_OPERATION( "ERR_02014_UNSUPPORTED_OPERATION" ),
>> ...
>>     ERR_04219_ARGUMENT1_NULL( "ERR_04219_ARGUMENT1_NULL" ),
>>     ERR_04220_ARGUMENT2_NULL( "ERR_04220_ARGUMENT2_NULL" ),
>> ...
>>     ERR_04442_NULL_AT_NOT_ALLOWED( "ERR_04442_NULL_AT_NOT_ALLOWED" ),
>> ...
>>     ERR_04457_NULL_ATTRIBUTE_ID( "ERR_04457_NULL_ATTRIBUTE_ID" ),
>> ...
>>     ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED( "ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED" ),
>> ...
>>     ERR_04477_NO_VALID_AT_FOR_THIS_ID( "ERR_04477_NO_VALID_AT_FOR_THIS_ID" ),
>>     ERR_04478_NO_VALUE_NOT_ALLOWED( "ERR_04478_NO_VALUE_NOT_ALLOWED" ),
>>     ERR_04479_INVALID_SYNTAX_VALUE( "ERR_04479_INVALID_SYNTAX_VALUE" ),
>> ...
>>     ERR_09001_DIRECTORY_CREATION_FAILED( "ERR_09001_DIRECTORY_CREATION_FAILED" ),
>> ...
>>     ERR_254_ADD_EXISTING_VALUE("ERR_254_ADD_EXISTING_VALUE"),
>> ...
>>   ERR_272_MODIFY_LEAVES_NO_STRUCTURAL_OBJECT_CLASS("ERR_272_MODIFY_LEAVES_NO_STRUCTURAL_OBJECT_CLASS"),
>> ...
>>     ERR_539_BAD_BLOCK_ID("ERR_539_BAD_BLOCK_ID"),
>>
>>
>>
>> We have something like one thousands of them, it will take time, but this approach works. Be patient :)
>>      
> No worries.  :) Why do they all have numbers in them?
>    

Grep is your friend when you have accurate elements to work on :) 
Numbers are less versatile than textual descriptions.

/me remember a 5 days debugging session on a production serveur 
generating 5Gb of logs a day, using grep to grab the errors I was 
looking for...


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com



Re: Exception Logging

Posted by Felix Knecht <fe...@apache.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> No worries.  :) Why do they all have numbers in them?

Because there's also a request to build a knowledgebase [1]. It's easier
having numbers to lookup something in a knowledgebase than having a text
which may occur multiple times and for different exceptions.

Felix

[1] https://issues.apache.org/jira/browse/DIRSERVER-886
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwJBloACgkQ2lZVCB08qHExZQCcDe2ah3Ecqcgi4AduLeeh0ghN
6hQAoNnlAKU3ly+4ejuZ42TSxaaMw3mj
=1Y7i
-----END PGP SIGNATURE-----

Re: Exception Logging

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Jun 4, 2010, at 6:13 AM, Emmanuel Lecharny wrote:

> On 6/4/10 2:55 PM, Alan D. Cabrera wrote:
>> 
>> Finally, what the heck is ERR_04007? :)  I thought there already was a discussion and community consensus about how there is little to negative value in using numbers as error messages.  Maybe I missed the conversation where this opinion was reversed.  If so, ignore this bit.  :)
>>   
> No, nobody missed this valid concern. We are just modifying them one by one when fixing issues using those error code :
> 
>    ERR_02014_UNSUPPORTED_OPERATION( "ERR_02014_UNSUPPORTED_OPERATION" ),
> ...
>    ERR_04219_ARGUMENT1_NULL( "ERR_04219_ARGUMENT1_NULL" ),
>    ERR_04220_ARGUMENT2_NULL( "ERR_04220_ARGUMENT2_NULL" ),
> ...
>    ERR_04442_NULL_AT_NOT_ALLOWED( "ERR_04442_NULL_AT_NOT_ALLOWED" ),
> ...
>    ERR_04457_NULL_ATTRIBUTE_ID( "ERR_04457_NULL_ATTRIBUTE_ID" ),
> ...
>    ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED( "ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED" ),
> ...
>    ERR_04477_NO_VALID_AT_FOR_THIS_ID( "ERR_04477_NO_VALID_AT_FOR_THIS_ID" ),
>    ERR_04478_NO_VALUE_NOT_ALLOWED( "ERR_04478_NO_VALUE_NOT_ALLOWED" ),
>    ERR_04479_INVALID_SYNTAX_VALUE( "ERR_04479_INVALID_SYNTAX_VALUE" ),
> ...
>    ERR_09001_DIRECTORY_CREATION_FAILED( "ERR_09001_DIRECTORY_CREATION_FAILED" ),
> ...
>    ERR_254_ADD_EXISTING_VALUE("ERR_254_ADD_EXISTING_VALUE"),
> ...
>  ERR_272_MODIFY_LEAVES_NO_STRUCTURAL_OBJECT_CLASS("ERR_272_MODIFY_LEAVES_NO_STRUCTURAL_OBJECT_CLASS"),
> ...
>    ERR_539_BAD_BLOCK_ID("ERR_539_BAD_BLOCK_ID"),
> 
> 
> 
> We have something like one thousands of them, it will take time, but this approach works. Be patient :)

No worries.  :) Why do they all have numbers in them?


Regards,
Alan


Re: Exception Logging

Posted by Emmanuel Lecharny <el...@gmail.com>.
On 6/4/10 2:55 PM, Alan D. Cabrera wrote:
>
> Finally, what the heck is ERR_04007? :)  I thought there already was a discussion and community consensus about how there is little to negative value in using numbers as error messages.  Maybe I missed the conversation where this opinion was reversed.  If so, ignore this bit.  :)
>    
No, nobody missed this valid concern. We are just modifying them one by 
one when fixing issues using those error code :

     ERR_02014_UNSUPPORTED_OPERATION( "ERR_02014_UNSUPPORTED_OPERATION" ),
...
     ERR_04219_ARGUMENT1_NULL( "ERR_04219_ARGUMENT1_NULL" ),
     ERR_04220_ARGUMENT2_NULL( "ERR_04220_ARGUMENT2_NULL" ),
...
     ERR_04442_NULL_AT_NOT_ALLOWED( "ERR_04442_NULL_AT_NOT_ALLOWED" ),
...
     ERR_04457_NULL_ATTRIBUTE_ID( "ERR_04457_NULL_ATTRIBUTE_ID" ),
...
     ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED( 
"ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED" ),
...
     ERR_04477_NO_VALID_AT_FOR_THIS_ID( 
"ERR_04477_NO_VALID_AT_FOR_THIS_ID" ),
     ERR_04478_NO_VALUE_NOT_ALLOWED( "ERR_04478_NO_VALUE_NOT_ALLOWED" ),
     ERR_04479_INVALID_SYNTAX_VALUE( "ERR_04479_INVALID_SYNTAX_VALUE" ),
...
     ERR_09001_DIRECTORY_CREATION_FAILED( 
"ERR_09001_DIRECTORY_CREATION_FAILED" ),
...
     ERR_254_ADD_EXISTING_VALUE("ERR_254_ADD_EXISTING_VALUE"),
...
   
ERR_272_MODIFY_LEAVES_NO_STRUCTURAL_OBJECT_CLASS("ERR_272_MODIFY_LEAVES_NO_STRUCTURAL_OBJECT_CLASS"),
...
     ERR_539_BAD_BLOCK_ID("ERR_539_BAD_BLOCK_ID"),



We have something like one thousands of them, it will take time, but 
this approach works. Be patient :)

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com



Re: Exception Logging

Posted by Alex Karasulu <ak...@apache.org>.
On Sat, Jun 5, 2010 at 11:35 AM, Alex Karasulu <ak...@apache.org> wrote:

> On Fri, Jun 4, 2010 at 3:55 PM, Alan D. Cabrera <li...@toolazydogs.com> wro
>
>>
>> On Jun 3, 2010, at 2:15 PM, Felix Knecht wrote:
>>
>> > -----BEGIN PGP SIGNED MESSAGE-----
>> > Hash: SHA1
>> >
>> > We have a lot of following constructs:
>> >
>> > log.error( I18n.err( I18n.ERR_04007 ) );
>> > throw new DecoderException( I18n.err( I18n.ERR_04007 ) );
>> >
>> > What about logging the exception within the exception itself like
>> >
>> > public DecoderException(String message)
>> > {
>> >    super( message );
>> >    log.error( message );
>> > }
>> >
>> >
>> > This will avoid having log.error all over the place and the translation
>> > must be done only once instead of twice like above.
>>
>> This is not a very good pattern for a number of reasons.
>>
>> First, you cannot control logging at the source of the error.  Admittedly
>> this is an error message but I have run into times where I want to turn off
>> the klaxon to see what the real problem is.
>>
>> Second, constructors should not have side effects.  It's never a good
>> idea.
>>
>> Third, I never log an error if I am throwing an exception.  It just adds
>> noise.  I will, however, log additional useful information that is not in
>> the exception message.  Just parroting what's in the exception is of little
>> value.
>>
>>
> +1
>
>
>> Finally, what the heck is ERR_04007? :)  I thought there already was a
>> discussion and community consensus about how there is little to negative
>> value in using numbers as error messages.  Maybe I missed the conversation
>> where this opinion was reversed.  If so, ignore this bit.  :)
>>
>>
> +1 - we need to find a way to make this easier to read either with the
> IDE's help or other.
>
>
Pardon I realized this was discussed further and that I had not read this
completely. Retracting the +1. Too much mail.

-- 
Alex Karasulu
My Blog :: http://www.jroller.com/akarasulu/
Apache Directory Server :: http://directory.apache.org
Apache MINA :: http://mina.apache.org
To set up a meeting with me: http://tungle.me/AlexKarasulu

Re: Exception Logging

Posted by Alex Karasulu <ak...@apache.org>.
On Fri, Jun 4, 2010 at 3:55 PM, Alan D. Cabrera <li...@toolazydogs.com> wro

>
> On Jun 3, 2010, at 2:15 PM, Felix Knecht wrote:
>
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > We have a lot of following constructs:
> >
> > log.error( I18n.err( I18n.ERR_04007 ) );
> > throw new DecoderException( I18n.err( I18n.ERR_04007 ) );
> >
> > What about logging the exception within the exception itself like
> >
> > public DecoderException(String message)
> > {
> >    super( message );
> >    log.error( message );
> > }
> >
> >
> > This will avoid having log.error all over the place and the translation
> > must be done only once instead of twice like above.
>
> This is not a very good pattern for a number of reasons.
>
> First, you cannot control logging at the source of the error.  Admittedly
> this is an error message but I have run into times where I want to turn off
> the klaxon to see what the real problem is.
>
> Second, constructors should not have side effects.  It's never a good idea.
>
> Third, I never log an error if I am throwing an exception.  It just adds
> noise.  I will, however, log additional useful information that is not in
> the exception message.  Just parroting what's in the exception is of little
> value.
>
>
+1


> Finally, what the heck is ERR_04007? :)  I thought there already was a
> discussion and community consensus about how there is little to negative
> value in using numbers as error messages.  Maybe I missed the conversation
> where this opinion was reversed.  If so, ignore this bit.  :)
>
>
+1 - we need to find a way to make this easier to read either with the IDE's
help or other.

-- 
Alex Karasulu
My Blog :: http://www.jroller.com/akarasulu/
Apache Directory Server :: http://directory.apache.org
Apache MINA :: http://mina.apache.org
To set up a meeting with me: http://tungle.me/AlexKarasulu

Re: Exception Logging

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Jun 3, 2010, at 2:15 PM, Felix Knecht wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> We have a lot of following constructs:
> 
> log.error( I18n.err( I18n.ERR_04007 ) );
> throw new DecoderException( I18n.err( I18n.ERR_04007 ) );
> 
> What about logging the exception within the exception itself like
> 
> public DecoderException(String message)
> {
>    super( message );
>    log.error( message );
> }
> 
> 
> This will avoid having log.error all over the place and the translation
> must be done only once instead of twice like above.

This is not a very good pattern for a number of reasons.

First, you cannot control logging at the source of the error.  Admittedly this is an error message but I have run into times where I want to turn off the klaxon to see what the real problem is.

Second, constructors should not have side effects.  It's never a good idea.

Third, I never log an error if I am throwing an exception.  It just adds noise.  I will, however, log additional useful information that is not in the exception message.  Just parroting what's in the exception is of little value.

Finally, what the heck is ERR_04007? :)  I thought there already was a discussion and community consensus about how there is little to negative value in using numbers as error messages.  Maybe I missed the conversation where this opinion was reversed.  If so, ignore this bit.  :)


Regards,
Alan




Re: Exception Logging

Posted by Felix Knecht <fe...@apache.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06/03/10 23:15, Felix Knecht wrote:
> We have a lot of following constructs:
> 
> log.error( I18n.err( I18n.ERR_04007 ) );
> throw new DecoderException( I18n.err( I18n.ERR_04007 ) );
> 
> What about logging the exception within the exception itself like
> 
> public DecoderException(String message)
> {
>     super( message );
>     log.error( message );

log.error( message, this ); // to have also the location where the
exception happend.

> }
> 
> 
> This will avoid having log.error all over the place and the translation
> must be done only once instead of twice like above.
> 
> Regards
> Felix
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwIH54ACgkQ2lZVCB08qHF3XACg0zklDOjBfOhP6rh7ZCzmaybH
7MMAoIcB+ldaB1gIDbperFMx0XD9QSqI
=3l2A
-----END PGP SIGNATURE-----

Re: Exception Logging

Posted by Alex Karasulu <ak...@apache.org>.
On Fri, Jun 4, 2010 at 12:41 AM, Emmanuel Lecharny <el...@gmail.com>wrote:

> On 6/3/10 11:15 PM, Felix Knecht wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> We have a lot of following constructs:
>>
>> log.error( I18n.err( I18n.ERR_04007 ) );
>> throw new DecoderException( I18n.err( I18n.ERR_04007 ) );
>>
>> What about logging the exception within the exception itself like
>>
>> public DecoderException(String message)
>> {
>>     super( message );
>>     log.error( message );
>> }
>>
>>
>> This will avoid having log.error all over the place and the translation
>> must be done only once instead of twice like above.
>>
>>
>
> I would not favor such code pattern. The reason is that we may not want to
> log in all cases, but only from time to time. Also the log can contain a
> different message.
>
> To avoid a double translation, I would rather suggest something like :
> String message =
>
> String message = I18n.err( I18n.ERR_04007 );
> log.error( message );
> throw new DecoderException( message );
>
>
+1

Also although perhaps unrelated ... can't we get eclipse to show the error
message when doing a mouse over or something on the I18n error code?

-- 
Alex Karasulu
My Blog :: http://www.jroller.com/akarasulu/
Apache Directory Server :: http://directory.apache.org
Apache MINA :: http://mina.apache.org
To set up a meeting with me: http://tungle.me/AlexKarasulu

Re: Exception Logging

Posted by Emmanuel Lecharny <el...@gmail.com>.
On 6/3/10 11:15 PM, Felix Knecht wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> We have a lot of following constructs:
>
> log.error( I18n.err( I18n.ERR_04007 ) );
> throw new DecoderException( I18n.err( I18n.ERR_04007 ) );
>
> What about logging the exception within the exception itself like
>
> public DecoderException(String message)
> {
>      super( message );
>      log.error( message );
> }
>
>
> This will avoid having log.error all over the place and the translation
> must be done only once instead of twice like above.
>    

I would not favor such code pattern. The reason is that we may not want 
to log in all cases, but only from time to time. Also the log can 
contain a different message.

To avoid a double translation, I would rather suggest something like :
String message =

String message = I18n.err( I18n.ERR_04007 );
log.error( message );
throw new DecoderException( message );


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com