java.util.logger

Discussion in 'Java' started by gwoodhouse@gmail.com, Sep 7, 2010.

  1. Guest

    Hello,

    I've recently been looking into a new system here and on the live
    system it uses the logger.properties file located in the tomcat/conf
    directory.

    Now, i've looked around google and i still don't feel like i'm on
    solid ground with this. On my local system i've tried putting a
    logger.properties file in my Tomcats conf directory and it still uses
    the logger.properties file in the jdk/jre/lib directory (If i remove
    it it simply logs nothing).

    I'm used to systems which use log4j which is set up in the web.xml so
    i'm trying to wrap my mind around this.

    How does the application know to look for a logger.properties file,
    and, where does it look for the logger.properties file and in what
    order?

    Help appreciated! :)

    Graeme
    , Sep 7, 2010
    #1
    1. Advertising

  2. Guest

    From google i understand you can change the logging level of specific
    packages, ie:

    com.example.JavaFile.level = WARN

    Can you also set the other options on a class/package per class/
    package basis? Ie,

    com.example.JavaFile.pattern = c:/JavaFile.xml
    , Sep 7, 2010
    #2
    1. Advertising

  3. Lew Guest

    On Sep 7, 11:53 am, "" <>
    wrote:
    > From google i understand you can change the logging level of specific
    > packages, ie:
    >
    > com.example.JavaFile.level = WARN
    >
    > Can you also set the other options on a class/package per class/
    > package basis? Ie,
    >
    > com.example.JavaFile.pattern = c:/JavaFile.xml
    Lew, Sep 7, 2010
    #3
  4. Lew Guest

    (Sorry about my blank post earlier. Slip of the hand.)

    wrote:
    > I've recently been looking into a new system here and on the live
    > system it uses the logger.properties file located in the tomcat/conf
    > directory.
    >
    > Now, i've [sic] looked around google and i [sic] still don't feel like i'm [sic] on
    > solid ground with this. On my local system i've [sic] tried putting a
    > logger.properties file in my Tomcats conf directory and it still uses
    > the logger.properties file in the jdk/jre/lib directory (If i [sic] remove
    > it it simply logs nothing).
    >
    > I'm used to systems which use log4j which is set up in the web.xml so
    > i'm [sic] trying to wrap my mind around this.
    >
    > How does the application know to look for a logger.properties file,
    > and, where does it look for the logger.properties file and in what
    > order?
    >


    For log4j, the exact details are actually documented (gasp!) on the
    log4j site:
    <http://logging.apache.org/log4j/1.2/manual.html>
    "Default Initialization Procedure"

    --
    Lew
    Lew, Sep 7, 2010
    #4
  5. Guest

    On Sep 7, 5:10 pm, Lew <> wrote:
    > (Sorry about my blank post earlier.  Slip of the hand.)
    >
    >
    >
    > wrote:
    > > I've recently been looking into a new system here and on the live
    > > system it uses the logger.properties file located in the tomcat/conf
    > > directory.

    >
    > > Now, i've [sic] looked around google and i [sic] still don't feel like i'm [sic] on
    > > solid ground with this. On my local system i've [sic] tried putting a
    > > logger.properties file in my Tomcats conf directory and it still uses
    > > the logger.properties file in the jdk/jre/lib directory (If i [sic] remove
    > > it it simply logs nothing).

    >
    > > I'm used to systems which use log4j which is set up in the web.xml so
    > > i'm [sic] trying to wrap my mind around this.

    >
    > > How does the application know to look for a logger.properties file,
    > > and, where does it look for the logger.properties file and in what
    > > order?

    >
    > For log4j, the exact details are actually documented (gasp!) on the
    > log4j site:
    > <http://logging.apache.org/log4j/1.2/manual.html>
    > "Default Initialization Procedure"
    >
    > --
    > Lew


    I'm not using log4j, i wish i was, the product is using
    java.util.logger therefore picking up logging.properties,
    , Sep 8, 2010
    #5
  6. Lew Guest

    Lew wrote:
    >> For log4j, the exact details are actually documented (gasp!) on the
    >> log4j site:
    >> <http://logging.apache.org/log4j/1.2/manual.html>
    >> "Default Initialization Procedure"


    wrote:
    > I'm not using log4j, i [sic] wish i [sic] was, the product is using
    > java.util.logger [sic] therefore picking up logging.properties,


    There is no "java.util.logger" package.

    The documentation for 'java.util.logging' mentions that the configuration file
    is in standard 'java.util.Properties' format. That implies that the file is
    loaded by the classloader mechanism, i.e., from the classpath. Try that and
    see if it works.

    Googling turn up about 383,000 results for "java.util.logging". Some of those
    might provide further detail.

    --
    Lew
    Lew, Sep 8, 2010
    #6
  7. Guest

    On Sep 8, 1:04 pm, Lew <> wrote:
    > Lew wrote:
    > >> For log4j, the exact details are actually documented (gasp!) on the
    > >> log4j site:
    > >> <http://logging.apache.org/log4j/1.2/manual.html>
    > >> "Default Initialization Procedure"

    > wrote:
    > > I'm not using log4j, i [sic] wish i [sic] was, the product is using
    > > java.util.logger [sic] therefore picking up logging.properties,

    >
    > There is no "java.util.logger" package.
    >
    > The documentation for 'java.util.logging' mentions that the configuration file
    > Lew


    Your right it is java.util.logging, sorry mistyped.

    On our production environment the logging.properties file is located
    in tomcat/conf, and it is using this file. I couldn't figure out why
    it was using this but i've found in the tomcat/bin/catalina.bat the
    line:

    AVA_OPTS=%JAVA_OPTS% -
    Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -
    Djava.util.logging.config.file="%CATALINA_BASE%\conf
    \logging.properties"

    Which explains why its there quite nicely. So thank you for your help
    with that.

    I'm still wondering though:
    Can you set a different logging location for different packages in the
    logging file?

    Does anyone know?
    , Sep 8, 2010
    #7
  8. "Lew" <> wrote in message
    news:i67u3c$h1s$...

    >
    > The documentation for 'java.util.logging' mentions that the configuration
    > file is in standard 'java.util.Properties' format. That implies that the
    > file is loaded by the classloader mechanism, i.e., from the classpath.


    No, it doesn't. In fact, the default location for logging.properties is in
    the JRE lib directory. If you want to put it elsewhere, you need to set one
    of two system properties:

    java.util.logging.config.file points to an alternate location for the file
    java.util.logging.config.class names a class responsible for reading the
    file
    Mike Schilling, Sep 8, 2010
    #8
  9. markspace Guest

    On 9/8/2010 6:24 AM, wrote:

    > Can you set a different logging location for different packages in the
    > logging file?



    <http://download.oracle.com/javase/6/docs/api/java/util/logging/LogManager.html>

    <http://download.oracle.com/javase/6/docs/api/java/util/logging/FileHandler.html>

    My reading of this suggests "no." You'll need to make some new logging
    classes (trivially extend the FileHandler class) in order to do so. The
    default configuration doesn't support named handlers, so you can only
    refer to a handler by it's class name, and that only gives you one of
    each type. So only one FileHandler, period, can be configured.

    I think you'll have to roll your own config file if you want more
    flexibility. You might be able to introduce named handlers into the
    logging properties, but you'd probably be better off to make your own
    ..properties file, since modify the default one could be really confusing.

    See the first link and the "java.util.logging.config.class" option for
    the best way to do this, imo.
    markspace, Sep 8, 2010
    #9
  10. Lew Guest

    Lew wrote:
    >> The documentation for 'java.util.logging' mentions that the configuration
    >> file is in standard 'java.util.Properties' format.  That implies that the
    >> file is loaded by the classloader mechanism, i.e., from the classpath.

    >


    Mike Schilling wrote:
    > No, it doesn't.  In fact, the default location for logging.properties is in
    > the JRE lib directory.  If you want to put it elsewhere, you need to set one
    > of two system properties:
    >
    > java.util.logging.config.file points to an alternate location for the file
    > java.util.logging.config.class names a class responsible for reading the
    > file


    Ah. Thanks for that correction.

    --
    Lew
    Lew, Sep 8, 2010
    #10
  11. markspace Guest

    On 9/8/2010 9:59 AM, markspace wrote:

    > See the first link and the "java.util.logging.config.class" option for
    > the best way to do this, imo.
    >



    I ended up implementing a test case of this using the "config" property
    in the logging.properties file instead of the system property above.
    This allowed me to reuse the bits of the existing logger configuration
    while extending new bits so I could add multiple file handlers.

    I added a configuration property to name handlers, and then configured
    each handler in turn, adding to the requested logger when complete.

    Rather than do this in a hard-coded manner, I made some support classes
    to assist with configuring the individual handlers. The main class,
    ConfigureHandlers, instantiates a helper class (which implements a
    builder pattern) configures each builder using reflection, then builds
    and installs the handler. It worked out pretty slick.

    The code is pretty rough still and needs more helper (builder) classes
    to support more handlers, and it needs many more test cases, but it
    seems to work fine and can be configured easily from the
    logging.properties file.
    markspace, Sep 9, 2010
    #11
  12. Guest

    On Sep 9, 3:37 am, markspace <> wrote:
    > I ended up implementing a test case of this using the "config" property
    > in the logging.properties file instead of the system property above.


    If you have any of the source Mark that would really help me
    understand whats going on.

    After all this it turns out the single part of code i need to log is
    being handled by some weird logger configured in a jar i have no
    source for. Go figure.

    Even so learning more about this for the rest of the code would be
    great.

    Graeme
    , Sep 9, 2010
    #12
  13. markspace Guest

    On 9/9/2010 3:24 AM, wrote:

    > After all this it turns out the single part of code i need to log is
    > being handled by some weird logger configured in a jar i have no
    > source for. Go figure.



    You understand I had to modify code to get this to work, right?

    Also, it occurs to me that if the app at some point does a mass logger
    reset, this configuration will be overridden. If the app has some
    "weird logger" then your options may be limited to modifying the code,
    and trying to use logging.properties may not help.

    Anyway, look up the "config" option in the LogManager. It just execute
    arbitrary code in the named classes.

    logging.properties:

    config = my.classname.Here

    Then in that class:

    package my.classname;
    public class Here {
    public Here() {
    Logger root = Logger.getLogger("");
    root.addHandler( new FileHandler( "/tmp/var/logs/applog.log" );
    Logger myLogger = Logger.getLogger( "my.otherpackage" );
    myLogger.addHandler( new FileHandler( "/home/me/myapplog.log" );
    }
    }

    Now this class needs to be accessible to the log manager as it runs the
    app. You could manually add it to the Jar/War file, adjust the
    classpath of the application via the command line, or put this class in
    some global location.
    markspace, Sep 9, 2010
    #13
  14. Guest

    Hello,

    Feeling dense by not being able to figure this out/use the docs to
    figure this out. Just isn't making sense to me.

    When your using java.util.logging and you have a logging.properties
    looking like so:

    handlers = 1catalina.org.apache.juli.FileHandler,
    2localhost.org.apache.juli.FileHandler

    1catalina.org.apache.juli.FileHandler.level = FINE
    1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/
    logs
    1catalina.org.apache.juli.FileHandler.prefix = catalina.

    2localhost.org.apache.juli.FileHandler.level = FINE
    2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/
    logs
    2localhost.org.apache.juli.FileHandler.prefix = localhost.

    org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level =
    INFO
    org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers
    = 2localhost.org.apache.juli.FileHandler

    How do you know when a specific file in the source is using a certain
    handler?

    Sorry for what is probably a stupid question (To those that know
    anyway)

    Graeme
    , Sep 15, 2010
    #14
  15. markspace Guest

    On 9/15/2010 6:26 AM, wrote:

    > How do you know when a specific file in the source is using a certain
    > handler?



    Wouldn't that be the prefix?

    <http://tomcat.apache.org/tomcat-5.5-doc/logging.html>
    markspace, Sep 15, 2010
    #15
  16. Guest

    On Sep 15, 5:52 pm, markspace <> wrote:
    > On 9/15/2010 6:26 AM, wrote:
    >
    > > How do you know when a specific file in the source is using a certain
    > > handler?

    >
    > Wouldn't that be the prefix?
    >
    > <http://tomcat.apache.org/tomcat-5.5-doc/logging.html>


    Aparently not

    For instance, a package named uk.co.graeme.display.DisplayPage is
    using 1catalina.org.apache.juli.FileHandler, I have no idea why.

    Graeme
    , Sep 27, 2010
    #16
  17. Daniel Pitts Guest

    On 9/27/2010 6:14 AM, wrote:
    > On Sep 15, 5:52 pm, markspace<> wrote:
    >> On 9/15/2010 6:26 AM, wrote:
    >>
    >>> How do you know when a specific file in the source is using a certain
    >>> handler?

    >>
    >> Wouldn't that be the prefix?
    >>
    >> <http://tomcat.apache.org/tomcat-5.5-doc/logging.html>

    >
    > Aparently not
    >
    > For instance, a package named uk.co.graeme.display.DisplayPage is
    > using 1catalina.org.apache.juli.FileHandler, I have no idea why.

    Perhaps a copy-and-past bug by the authors who wrote DisplayPage?


    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
    Daniel Pitts, Sep 27, 2010
    #17
  18. markspace Guest

    On 9/27/2010 6:14 AM, wrote:

    >
    > For instance, a package named uk.co.graeme.display.DisplayPage is
    > using 1catalina.org.apache.juli.FileHandler, I have no idea why.



    I was going to say the same thing as Daniel. It looks like someone just
    copied the configuration file from the link I sent you verbatim.
    Possibly lazy or didn't understand or just forgot to go back and change it.
    markspace, Sep 27, 2010
    #18
  19. Guest

    On Sep 27, 6:44 pm, markspace <> wrote:
    > On 9/27/2010 6:14 AM, wrote:
    >
    >
    >
    > > For instance, a package named uk.co.graeme.display.DisplayPage is
    > > using 1catalina.org.apache.juli.FileHandler, I have no idea why.

    >
    > I was going to say the same thing as Daniel.  It looks like someone just
    > copied the configuration file from the link I sent you verbatim.
    > Possibly lazy or didn't understand or just forgot to go back and change it.


    Hi Mark, Daniel, All

    Hopefully you can help me some more with this. I'm still absolutely
    clueless. I must be missing something really obvious.

    This is my logging.properties file:
    -----------
    handlers = 1catalina.org.apache.juli.FileHandler,
    2localhost.org.apache.juli.FileHandler,
    3manager.org.apache.juli.FileHandler,
    4admin.org.apache.juli.FileHandler, 5host-
    manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

    ..handlers = 1catalina.org.apache.juli.FileHandler,
    java.util.logging.ConsoleHandler

    ############################################################
    # Handler specific properties.
    # Describes specific configuration info for Handlers.
    ############################################################

    1catalina.org.apache.juli.FileHandler.level = FINE
    1catalina.org.apache.juli.FileHandler.directory = D:\\opt\\logs
    1catalina.org.apache.juli.FileHandler.prefix = catalina.

    2localhost.org.apache.juli.FileHandler.level = FINE
    2localhost.org.apache.juli.FileHandler.directory = D:\\opt\\logs
    2localhost.org.apache.juli.FileHandler.prefix = localhost.

    3manager.org.apache.juli.FileHandler.level = FINE
    3manager.org.apache.juli.FileHandler.directory = D:\\opt\\logs
    3manager.org.apache.juli.FileHandler.prefix = manager.

    4admin.org.apache.juli.FileHandler.level = FINE
    4admin.org.apache.juli.FileHandler.directory = D:\\opt\\logs
    4admin.org.apache.juli.FileHandler.prefix = admin.

    5host-manager.org.apache.juli.FileHandler.level = FINE
    5host-manager.org.apache.juli.FileHandler.directory = D:\\opt\\logs
    5host-manager.org.apache.juli.FileHandler.prefix = host-manager.

    java.util.logging.ConsoleHandler.level = FINE
    java.util.logging.ConsoleHandler.formatter =
    java.util.logging.SimpleFormatter


    ############################################################
    # Facility specific properties.
    # Provides extra control for each logger.
    ############################################################

    org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level =
    INFO
    org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers
    = 2localhost.org.apache.juli.FileHandler

    org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/
    manager].level = INFO
    org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/
    manager].handlers = 3manager.org.apache.juli.FileHandler

    org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/
    admin].level = INFO
    org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/
    admin].handlers = 4admin.org.apache.juli.FileHandler

    org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-
    manager].level = INFO
    org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-
    manager].handlers = 5host-manager.org.apache.juli.FileHandler
    --------------------

    As you can see, this is pretty much the entire log file as default.
    Tomcat is set to use this file with the argument:
    -Djava.util.logging.config.file=D:\opt\tomcat\conf\logging.properties

    Now, i've re-looked through the documentation and i still have no
    understanding whatsoever of why a certain class is logging through one
    handler and not another. For instance, this is a class file (Stripped
    of company specific names etc):

    package uk.co.graeme.layout.element.register;
    ....
    public class RegistrationEmail {
    ...
    private static Logger LOG =
    Logger.getLogger(RegistrationEmail.class.getName());

    private String evaluate(VelocityEngine ve, VelocityContext
    context, String template) {
    StringWriter writer = new StringWriter();

    try {
    ve.evaluate(context, writer, null, template);
    } catch (Exception e) {
    LOG.log(Level.WARNING, "Unable to merge body of
    confirmation email", e);
    return template;
    }

    return writer.toString();
    }
    ...
    }

    Now, i have no idea where that log is going to end up. I'm actually
    assuming it will end up in the catalina.out file controlled by the
    1catalina handler, thats only because thats where 90% of our logs go
    (and because this class is reached through the path /register which
    isn't /manager, /admin/ etc etc.

    Hopefully someone can please explain to me, how is it using that
    handler rather than any other handler (And given we have no /manager, /
    admin portions of the sites, that 10% of the logs go to localhost.out)

    Please help because this has been bugging me for months without
    actually figuring out whats happeneing.

    Graeme Woodhouse
    , Nov 9, 2010
    #19
  20. markspace Guest

    A few questions.

    On 11/9/2010 2:48 AM, wrote:
    >
    > This is my logging.properties file:


    Which file where, exactly? It matters.

    > handlers = 1catalina.org.apache.juli.FileHandler,
    > 2localhost.org.apache.juli.FileHandler,
    > 3manager.org.apache.juli.FileHandler,
    > 4admin.org.apache.juli.FileHandler, 5host-
    > manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
    >
    > ..handlers = 1catalina.org.apache.juli.FileHandler,
    > java.util.logging.ConsoleHandler



    One of those "handlers" has no dots in front, the other has one (or
    maybe two, if my quoting didn't produce an error).

    Which way is correct?


    > public class RegistrationEmail {
    > ...
    > private static Logger LOG =
    > Logger.getLogger(RegistrationEmail.class.getName());
    >


    What's the full class name of Logger here?
    markspace, Nov 9, 2010
    #20
    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. CD1
    Replies:
    3
    Views:
    18,506
  2. sachin
    Replies:
    1
    Views:
    959
    Soren Kuula
    Feb 3, 2006
  3. Gugle
    Replies:
    3
    Views:
    1,235
    Gugle
    Dec 12, 2006
  4. Royan
    Replies:
    1
    Views:
    1,431
    Andrea Francia
    Apr 1, 2008
  5. cteb
    Replies:
    5
    Views:
    7,282
    Arne Vajhøj
    Oct 5, 2008
Loading...

Share This Page