Lew said:
You do ask very good questions.
Each program should have its own log. I don't know what you mean when
you say "project", but conventionally a project is tied to one
specific program or application.
And as there is a different target for each archer, there should be a
different log for each program.
Really, I've already given you the advice you need to answer your own
question. I told you to design logs to benefit people who need them to
troubleshoot.
How will it help an operations engineer or reliability engineer to
have to sift through dozens of applications' output to find what they
need? It's bad enough to sift through one application's log,
especially the way most programmers fail to think through their
logging output.
I'm 100% in agreement with you. I would certainly lean toward fewer logs
than more logs. I would embrace One Big Log long before I would choose to
have a separate log for each class!
I must have remembered this wrong. I coulda sworn someone suggested to
use the "-D" option per
<
http://docs.oracle.com/javase/7/docs/technotes/guides/logging/overview
.html> which in the section entitled "Configuration File"
<
http://docs.oracle.com/javase/7/docs/technotes/guides/logging/overview
.html#a1.8> points you to "See the LogManager API Specification for
details."
<
http://docs.oracle.com/javase/7/docs/api/java/util/logging/LogManager.
html> where it tells you
As I said, I remember seeing something about a -D option too. But I tried
REALLY hard to find it again and couldn't. I still don't know where that
post went. So thanks for repeating the information.
«In addition, the LogManager uses two optional system properties that
allow more control over reading the initial configuration:
"java.util.logging.config.class"
"java.util.logging.config.file"
These two properties may be set via the Preferences API, or as command
line property definitions to the "java" command, or as system property
definitions passed to JNI_CreateJavaVM.»
I don't have these link chains memorized, dude. I'm literally reading
the documentation on your behalf and reporting what I discover.
There's only so far you can get as a programmer asking others to read
the documentation for you.
Sorry, I do get a bit lazy on occasion. Just say no if you sense that
happening. But I really couldn't find those links and I spent at least a
half hour looking.
study the Javadocs for
'getResource[AsStream]()'.
Do I actually need to open the logging.properties file and read it,
as if it were a routine text file, to find the desired log path? That
seems improbable....
I'm only suggesting you study those Javadocs to understand how the
system searches for resources.
For what it's worth, someone else told me to add it to the classpath
for the project so I went into Run Configurations, chose the
Classpath tab and added the folder containing logging.properties
under "User Entries". I also
Umm - cargo cult.
In retrospect, yes, you're right. If I had found those links again or
tried a different google search, I might have found that pesky -
Djava.util.logging.config.file parameter and realized it was the
linchpin. But I was going crazy trying to find that darned log file so
that I could actually TRY some of the things people have been suggesting.
Didn't someone already ask you to share your logging.properties file
with us? Have you done so?
Yes, I did. But this thread is so unwieldy now that it's hard to find
things again. I'm having to click on a great many of the posts in the
thread just to find things. I'm in mid-conversation with several people
at the same time but I can't find any way to bookmark individual posts in
this newsreader....
Regardless, you are asking questions now that the documentation
answers. I have read the documentation for you and reported what I
found, to a degree.
So will your next post be another request to read the documentation
for you?
No, that will not be necessary. You didn't hear from me yesterday and
that's because I had a great day yesterday. I finally put that
-Djava.util.logging.config.file parameter in my VM arguments and pointed
it to my logging.properties file. I can finally see the bleeping log that
I'm writing!!!
And that let me get a great deal of useful work done. I reworked my Foo
and Common projects so that no loggers or locales are passed between
classes. In each class that needs to do logging - and no others, I do a
Logger logger = Logger.getLogger(getClass().getName());
In classes where only one or two methods do logging, logger is a local
variable. In classes where lots of methods do logging, I make it an
instance variable and instantiate it in the constructor.
I've become very fond of logging.properties because I figured out how to
assign my desired custom formatter there rather than having to do it
programmatically. I was very surprised to find that I was getting log
records from various java.awt.*, java.swing.*, and sun.* classes but I
keep all but the WARNING and SEVERE ones out of the log via the
appropriate lines in the logging.properties file.
In short, I am a lot closer to doing logging the way it is supposed to be
done rather than the messed-up way I was doing it before. I still need to
work with it a bit to fine-tune my approach to what should be logged and
what the exact level and content of each log record should be but that is
going to be an ongoing thing.
I even understand that advice in the article which Arved recommended
where the author said not to put the class name in the log record. Now
that I've got the actual class name as the Logger value in the record, I
can see that I don't need it again elsewhere in the same log record.
I know that some people do really well by just hearing principles and
concepts; with that under their belts, they can do exactly what needs to
be done with minimal hesitation. But I tend to need to see things
actually working with my own two eyes for concepts and principles to gel
properly. Before that, I'm not sure if I'm really envisioning things
accurately. That's why I was getting so antsy about seeing that log. Now
that I can see and try things and see real log records, things are
starting to solidify for me.
So thank you (everyone who contributed to this thread but especially Lew)
VERY MUCH for your patience.
I'll go try finishing up any dangling conversations within this thread
now and then get on to my next issue ;-)