java.util.logger

G

gwoodhouse

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
 
G

gwoodhouse

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
 
L

Lew

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
 
L

Lew

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

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"
 
G

gwoodhouse

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



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"

I'm not using log4j, i wish i was, the product is using
java.util.logger therefore picking up logging.properties,
 
L

Lew

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.
 
G

gwoodhouse

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?
 
M

Mike Schilling

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
 
M

markspace

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.
 
L

Lew

Mike said:
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.
 
M

markspace

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.
 
G

gwoodhouse

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
 
M

markspace

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.
 
G

gwoodhouse

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
 
D

Daniel Pitts

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?
 
M

markspace

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.
 
G

gwoodhouse

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
 
M

markspace

A few questions.

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?
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top