Re: Java Logger
- From: Pete <vwbora@xxxxxxxxxx>
- Date: Fri, 9 Jan 2009 03:15:49 -0800 (PST)
On Jan 9, 8:51 am, Simon <count.numb...@xxxxxx> wrote:
Pete wrote:
On Jan 8, 9:50 pm, Simon <count.numb...@xxxxxx> wrote: I have tried to follow
the documentation and like you said it is not straight forward, certainly not
for me.
You are right, It's tricky.
All I am trying to do is get the above small program to generate output for
the "entering & exiting" calls. I am not using a console Handler in the code,
as you can see.
You might be using it without knowing, though this is not defined "in the code",
but, as you found out yourself, here:
I don't really understand this. However, I notice in the
jre\lib\logging.properties file the following line :-
handlers= java.util.logging.ConsoleHandler
Your suggestions of java.util.logging.ConsoleHandler.level = ALL should that
go in program ? if so, the compiler complained of not being to resolve.
No, it is not Java code. It goes into the logging.properties file. Every Handler
uses its own set of properties. E.g. for the ConsoleHandler, read
http://java.sun.com/javase/6/docs/api/java/util/logging/ConsoleHandle...
It has the same effect as the solution posted by Knute and Mike.
If you decide to make these settings programmatically in this way, note that
this prevents the user from customizing the logging behaviour. One way out would
be to go with a properties file which you specify e.g. on the command line as I
suggested in my previous posting. If you don't want to do that, you can still do
it programmatically by using the following mechanism (taken fromhttp://java.sun.com/javase/6/docs/api/java/util/logging/LogManager.html)
If the "java.util.logging.config.class" property is set, then the property
value is treated as a class name. The given class will be loaded, an object
will be instantiated, and that object's constructor is responsible for
reading in the initial configuration. (That object may use other system
properties to control its configuration.) The alternate configuration class
can use readConfiguration(InputStream) to define properties in the
LogManager.
In other words, copy the code posted by Knute to the constructor of a class, say
MyLoggingConfig, point the said property to this class, e.g. using the -D switch
of java:
java -Djava.util.logging.config.class=MyLoggingConfig MainClass
Not particularly beautiful to trigger side effects from a constructor, though,
but it leaves the user the possibility to customize logging.
Cheers,
Simon
Gents,
Many thanks for both educational and help response. I should have said
before, why I was interested in the Logger class. I am doing my
assignment for the SCJD exam and using Andrew Monkhouse's book which
an example project in it. You may be aware of this. It uses the Logger
class in it. So I decided to understand the working of the Logger
using what I thought was a simple program, but not aware that this
simple program use the "jre\lib\logging.properties" file which
affected it.
There is no requirement for the SCJD to use the Logger in the
assignment. So for me to use it, would be used via the properties and
not introduce any Logger specific code in the assignment - except for
the log methods ( log, entering, exiting).
Simon. would you be able to send me a example config file as you
suggested in your initial response. Presumably this will specific for
the ConsoleHandler.
I still have one questions, in my orginal program, logger.log()
generated output however not logger.entering() or logger.exiting().
This suggests that the ConsoleHandler has no effect on the log(). Is
this correct ?
Once again many thanks.
Pete
.
- Follow-Ups:
- Re: Java Logger
- From: Simon
- Re: Java Logger
- References:
- Java Logger
- From: Pete
- Re: Java Logger
- From: Donkey Hottie
- Re: Java Logger
- From: Pete
- Re: Java Logger
- From: Simon
- Re: Java Logger
- From: Pete
- Re: Java Logger
- From: Simon
- Java Logger
- Prev by Date: Code coverage on a live application
- Next by Date: Re: How to assign a new title to a java command line output window (under windows)?
- Previous by thread: Re: Java Logger
- Next by thread: Re: Java Logger
- Index(es):
Relevant Pages
|