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
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
gwoodho...@gmail.com 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,
gwoodho...@gmail.com 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
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?
"Lew" <no...@lewscanon.com> wrote in message
news:i67u3c$h1s$1...@news.albasani.net...
>
> 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
> 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.
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
> 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.
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
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
> How do you know when a specific file in the source is using a certain
> handler?
Wouldn't that be the prefix?
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
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
>
> 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
On 11/9/2010 2:48 AM, gwood...@gmail.com 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?
> > This is my logging.properties file:
> Which file where, exactly? It matters.
tomcat/conf/logging.properties as specified in the tomcat startup by:
-Djava.util.logging.config.file=D:\opt\tomcat\conf\logging.properties
> > 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.
>
> Which way is correct?
Both lines are present in the logging file by default. One with a
preceding dot and one without a dot. I've read that a preceding .
means that the line is a global rather than local setting. At this
point i can't remember where i read that or the real meaning behind
this.
> > public class RegistrationEmail {
> > ...
> > private static LoggerLOG=
> > Logger.getLogger(RegistrationEmail.class.getName());
>
> What's the full class name of Logger here?
Logger is being imported from java.util.logging.Logger where as
RegistrationEmail is in the uk.co.graeme.layout.element.register
package.
Hope that helps you in figuring out where this would log and how you
come to that answer.
Thanks in advance!
Graeme
This won't work because....
>>> private static LoggerLOG=
>>> Logger.getLogger(RegistrationEmail.class.getName());
>>
>> What's the full class name of Logger here?
>
> Logger is being imported from java.util.logging.Logger
java.util.logging.Logger does not use the same style config file as
org.apache.log4j.Logger.
Log4j understands the style of log configuration you quoted, but you
aren't using Log4j. You're using the standard logger from Sun. Please
RTFM.
Hi Mark,
I think your confusing yourself. The log file i'm using is the default
JULI logging.properties (You can see the example in the URL you
yourself posted on Sep 15, 4:52 pm - http://tomcat.apache.org/tomcat-5.5-doc/logging.html).
You can see that if you "RTFM" that JULI and log4j are different
logging systems - further that i'm using both the java code to access
JULI and the properties file format for JULI. I'm asking a question
about JULI.
Just to clarify, I'm not currently using log4j nor am I asking any
questions about it. I have experience with log4j and understand it.
JULI i don't.
So the question still stands. In the JULI (java.util.logging) system,
how can you tell which handler will be used when you perform a logging
task from within a java file.
I think this thread may have currupted itself mostly from my own
inaccurate question so I will repost with the question stated more
clearly.
Graeme