Logging introduction

H

Hendrik Maryns

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

Hi all,

After seeing part of the discussion on exceptions, I decided my
application has matured enough that it deserves logging. I’ve been
happy with console messages as long as I was developing, but now I have
testers, and the log files would be useful.

I read the basic document on logging
(http://java.sun.com/javase/6/docs/technotes/guides/logging/overview.html),
and also http://www.onjava.com/pub/a/onjava/2002/06/19/log.html, but the
examples in the first are rather concise, and the second contains errors
(there is no such thing as
LogManager.getLogManager().setLevel("logging", Level.FINE);).

To make it short, I found no simple introduction in how to set up a
system with logging, or rather: what is common practice. Like: what
variables do you declare, typical setup for a Swing application, what is
a good value for the limit argument of FileHandler(String pattern, int
limit, int count) etc. etc.

An introduction, anyone?

TIA, H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFIUSP8e+7xMGD3itQRApfmAJ9WDKjyQxIH3KdxCfoilvg50IAY0gCdGWrL
MEFoeLWJgD50vY1wdlMOr74=
=MQtY
-----END PGP SIGNATURE-----
 
H

Hendrik Maryns

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

Hendrik Maryns schreef:
| Hi all,
|
| After seeing part of the discussion on exceptions, I decided my
| application has matured enough that it deserves logging. I’ve been
| happy with console messages as long as I was developing, but now I have
| testers, and the log files would be useful.
|
| I read the basic document on logging
|
(http://java.sun.com/javase/6/docs/technotes/guides/logging/overview.html),
| and also http://www.onjava.com/pub/a/onjava/2002/06/19/log.html, but the
| examples in the first are rather concise, and the second contains errors
| (there is no such thing as
| LogManager.getLogManager().setLevel("logging", Level.FINE);).
|
| To make it short, I found no simple introduction in how to set up a
| system with logging, or rather: what is common practice. Like: what
| variables do you declare, typical setup for a Swing application, what is
| a good value for the limit argument of FileHandler(String pattern, int
| limit, int count) etc. etc.
|
| An introduction, anyone?

Ok, http://mindprod.com/jgloss/logging.html is a good start, but I’d
still like some experience reports…

Cheers, H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFIUSd5e+7xMGD3itQRAh8xAJ9aEBDjx9JmjdAcC/3jlK7lSs4mQgCcDhZo
VB6o8zGrQLNw0eoC0Uk6xu0=
=o8xS
-----END PGP SIGNATURE-----
 
A

Arne Vajhøj

Hendrik said:
I read the basic document on logging
(http://java.sun.com/javase/6/docs/technotes/guides/logging/overview.html),
and also http://www.onjava.com/pub/a/onjava/2002/06/19/log.html, but the
examples in the first are rather concise, and the second contains errors
(there is no such thing as
LogManager.getLogManager().setLevel("logging", Level.FINE);).
To make it short, I found no simple introduction in how to set up a
system with logging, or rather: what is common practice. Like: what
variables do you declare, typical setup for a Swing application, what is
a good value for the limit argument of FileHandler(String pattern, int
limit, int count) etc. etc.

An introduction, anyone?

My guess would be that the OnJava article was written for a beta
version of 1.4.

java.util.logging is rather simple - I would say that the
first link should be sufficient to get you going.

Arne
 
A

Arne Vajhøj

Lew said:
I use log4j for apps, too. I've never before encountered the notion
that it's only for Java EE apps. Interesting perspective.

The online documentation for log4j indicates a very clear intent that it
be used for Java SE applications. The first example in the introductory
material,
<http://logging.apache.org/log4j/1.2/manual.html>,
shows a class with a main() and logging.

I agree that most apps don't need much in the way of advanced features
from log4j, but that applies to Java EE apps as much as Java SE apps in
my experience.

Personally, I don't find java.util.logging easier to use or deploy than
log4j. YMMV.

Since java.util.logging comes bundled with Java while log4j
does not then ...

That means an extra jar file for a Java SE app.

It does not mean anything for a Java EE app, because log4j
will already be there, because either the server itself or
one of the used frameworks already use it.

Arne
 
A

Arne Vajhøj

Lew said:
Good points. I believe my preference is at least in part due to
imprinting, since I learned log4j first.

However, adding JAR files to applications is far from outré, and the
log4j JAR is particularly helpful. I find log4j's style easier in the
code, if slightly harder in the deployment.

I would not recommend that people use log4j over java.util.logging on
the basis of my personal preference, of course. I find it likely that
you are correct, and that my preference is subjective, only. If it
comes down to advice, I would recommend that people follow your
suggestions.

I like log4j too.

There are several areas where I think it is better. More functionality,
better defaults, better performance etc..

But sometimes the simple tool is good enough.

I really think SUN should have included log4j in Java instead
of coming up with their own.

Now we can (at the server side) end up having 15 frameworks
that use log4j and 5 that use commons logging - yuck !

(I assume that no java.util.logging would mean no commons
logging - I have never seen any of other supported loggers
in real life)

Arne


Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top