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 Ma...@cms400.com on 2002/08/27 21:29:48 UTC

Logging idioms or guidelines: anyone have some?

My boss is away, so I'm taking the opportuinity to clean up my code. I have
a set of standards I use for style, formatting, documentation, naming etc.
I also have a set of coding idioms I like to follow (Law of Demeter, code
metric limits, etc).

My problem is I don't yet have a set of logging idioms, and it shows up in
my sporradic logging style.
So I'm interested in a "best practices" of logging, or a logging
"standard".

*Specifically* one that is based on something that makes it arguably
superior to other standards.

For example, do you log just before you do something:
  logger.debug("connecting to the database");
or after
   logger.debug("connected to the database");
or both?
Do you log when you throw an exception, catch one, or both?
etc...

Preachers of aspect oriented programming might not mind seeing a logging
statement at the entry and exit of every method. Some would certainly find
this to be overkill.

What do you all think?



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Logging idioms or guidelines: anyone have some?

Posted by Eric Jain <Er...@isb-sib.ch>.
> an iso-standard for logging? that made me curious. but the
> iso-website claims to be unaware of a standard with that number.
> where can i get some information about it?

I was just joking, though there is in fact a standard, ISO/IEC-17799:2000.
This standard describes security measures and contains a section on logging
in this context. There is a summary at
http://www.systemexperts.com/tutors/17799.pdf.


--
Eric Jain



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Logging idioms or guidelines: anyone have some?

Posted by peter riegersperger <ri...@subnet.at>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> > So I'm interested in a "best practices" of logging, or a logging
> > "standard".
> 
> Have a look at ISO-23544-5.
> 

an iso-standard for logging? that made me curious. but the
iso-website claims to be unaware of a standard with that number.
where can i get some information about it?

thanks,

rick


|-
| peter riegersperger  <ri...@subnet.at>
|-
| subnet
| platform for media art and experimental technologies
|-
| http://www.subnet.at/
|-
| muehlbacherhofweg 5 // 5020 salzburg // austria
|-
| fon/fax +43/662/842 897
|-

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>
Comment: public key available at http://home.subnet.at/rick/pgp/

iQA/AwUBPWzFaiDD9/SWDsvSEQKxcACeMtCnHxSoGv8PHKvHhJxEt8xMoGEAnRT+
2RyJcjZTnZdV8zAjpXNVkdA+
=1bay
-----END PGP SIGNATURE-----


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Logging idioms or guidelines: anyone have some?

Posted by Eric Jain <Er...@isb-sib.ch>.
> So I'm interested in a "best practices" of logging, or a logging
> "standard".

Have a look at ISO-23544-5.

Seriously, appart from being consistant I doubt there is any single best way
to do it.

You should of course keep in mind why exactely it is that you are logging,
as this influences the amount, distribution and form of log statements. Some
use cases are:

- Debug or monitor new or immature code
- Generate reports on usage patterns
- Trigger alerts on critical failures


> For example, do you log just before you do something:

Obviously it's a good idea to log before and after operations that take a
relatively long time or might hang or simply fail.

log.debug("Connecting to x")
try:
    ...
catch:
    log.error("Couldn't connect to x", e)
    throw e
log.info("Connected to x in " + t + "ms")


I usually log errors when I catch them (and before I rethrow them, if),
since more often than not I am not the one who threw them in the first
place.


--
Eric Jain



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>