Logging introduction

Discussion in 'Java' started by Hendrik Maryns, Jun 12, 2008.

  1. -----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-----
    Hendrik Maryns, Jun 12, 2008
    #1
    1. Advertising

  2. -----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-----
    Hendrik Maryns, Jun 12, 2008
    #2
    1. Advertising

  3. Hendrik Maryns

    Evans Guest

    Most of the articles you will come across online jump right into how
    they implement the loggings, but not the basic reasons or simple intro
    on how to implement them.

    But a quick google search is likely to dig up a few some nice intro...
    check out the link below and see if it helps at all.
    http://www.developer.com/java/other/article.php/1404951

    Good luck,

    Evans
    http://www.onyxtic.com
    Evans, Jun 12, 2008
    #3
  4. Hendrik Maryns wrote:
    > 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
    Arne Vajhøj, Jun 17, 2008
    #4
  5. Lew wrote:
    > Hendrik Maryns wrote:
    >> Ok, http://mindprod.com/jgloss/logging.html is a good start, but I’d
    >> still like some experience reports…

    >
    > I prefer Apache log4j.
    > <http://logging.apache.org/log4j/1.2/index.html>


    Me too.

    But that is for Java EE apps.

    For Java SE apps java.util.logging is easier to deploy
    and probably does not need the advanced features log4j offers.

    Arne
    Arne Vajhøj, Jun 17, 2008
    #5
  6. Lew wrote:
    > Lew wrote:
    >>> I prefer Apache log4j.
    >>> <http://logging.apache.org/log4j/1.2/index.html>

    >
    > Arne Vajhøj wrote:
    >> Me too.
    >>
    >> But that is for Java EE apps.
    >>
    >> For Java SE apps java.util.logging is easier to deploy
    >> and probably does not need the advanced features log4j offers.

    >
    > 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
    Arne Vajhøj, Jun 17, 2008
    #6
  7. Lew wrote:
    > Arne Vajhøj wrote:
    >> 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.

    >
    > 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
    Arne Vajhøj, Jun 18, 2008
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    0
    Views:
    941
    Stefan Siegl
    Aug 27, 2003
  2. janne
    Replies:
    0
    Views:
    9,448
    janne
    Sep 10, 2004
  3. Christoph Haas
    Replies:
    0
    Views:
    431
    Christoph Haas
    Jun 12, 2006
  4. Christoph Haas
    Replies:
    1
    Views:
    441
    Vinay Sajip
    Jun 14, 2006
  5. johnny
    Replies:
    1
    Views:
    623
    Dennis Lee Bieber
    Dec 12, 2006
Loading...

Share This Page