Lew said:
The sentence began with "You don't...". I fail to see what can be
confusing there. An appositive phrase doesn't invert the sense of the
predicate.
Which leaves the question of how we got the miscommunication in the
first place, when I never suggested such a thing.
Okay, let's not flog this to death. I just want to figure this out, not
get into a detailed post mortem about what you meant and what I thought
you meant and all of that.
I've apparently jumped to some (several?) wrong conclusions. I admit
that. I'm trying to listen and work with what you're telling me but I'm
not quite getting things yet.
"Seemed" foists the responsibility off. I didn't do the "seeming".
Okay, it was all me then. Everything you've said has been crystal clear
and no reasonable human being could possibly misunderstand what you were
saying or implying.
...
I used the term in the exact same sense as the logging library
documentation and in computer programming generally.
Again, I've got some gaps in my education. Those are my fault, not yours.
I'm just trying to understand what you say. When I get confused, I echo
back to see if I've got things right. So far, I'm not doing too well.
Fair enough.
I have now. It doesn't help much though; I knew all of that stuff before.
Figuring out how to apply it to my situation is where I seem to be having
trouble.
Don't presume; design. It is very possible that the "Foo" project
will not have a package 'com.novice.foo', if it has
'com.novice.foo.qux', 'com.novice.foo.bleh' and so on.
Sure. Foo actually contains two programs, the main one which uses a file
to drive an application and a support program which simplifies the
editing of the file that drives the main program. Those could possibly be
in different packages within the same project, com.novice.foo.bart and
com.novice.foo.homer. But to my way of thinking, they are such close
cousins that they may just as well be in the same package.
No, it won't. First, you have completely ignored that I said "one
logger per class". How did you distort that into "one logger per
package"? Second, you don't design packages for the logger, you design
loggers for the packages.
Sorry, you're right. I muddled the two together.
Not yet.
STOP!
I don't know how you make these leaps, and I am defeated as to how to
advise you not to. You go on for paragraphs about bad ideas that were
never suggested to you.
Sorry, one mistake just leads to the next. Let me rephrase.
Assuming that project Foo has a single package, com.novice.foo and three
classes, hickory, dickory, and dock, class hickory's logger would be
"com.novice.foo.hickory", class dickory's logger would be
"com.novice.foo.dickory" and class dock's logger would be
"com.novice.foo.dock".
Is that right now?
Once again, I repeat, and you may recall the Javadoc quotes I provided
upthread on this matter, getting a logger with a particular name gets
a reference to that same-named logger. Already. Without additional
complication on your part. It's built in. You don't need to reinvent
it. It already happens. All you have to do is give the same name. You
will already have gotten the reference. You don't have to pass it
anywhere. It's already there. Read the Javadocs. Again. And again. And
again. And again. Don't read what isn't in there - read what it says.
It says that if you give the 'getLogger()' the same name, it will
return a reference to the same logger.
Yes, of course, you're absolutely right. I forgot that.
Aside from that, I have no idea at all what you intend to say by, "so
that they write to the logger used by the instantiating class from
Foo". What precisely do you mean there?
It doesn't really matter. In fact it's dumb; I still had the thought in
my brain that the main program was going to pass its logger to each class
that it instantiates it but it's not. Each class is going to be getting
it's own logger with
Logger logger Logger.getLogger(getClass().getName());
READ THE TUTORIAL!
It is better to group types into packages.
Yes, every class is already in one or another named package and has been
for a long time. I'm still struggling a bit over which classes belong in
the SAME package and which should not.
My thinking is that classes in the Common PROJECT should also be in
packages that are distinct from the packages used for Projects Foo or
Bar, which will have names like "com.novice.foo" and "com.novice.bar".
I think I want "com.novice.common" for the classes in the Common project
but I'm not sure if all classes in Common should be in the same package
or if it is better to group similar classes within the Common project
into distinct packages like "com.novice.common.lookups",
"com.novice.common.utilities", etc. etc. I'm not seeing a huge benefit to
separate packages although I'm using separate packages now so that
similar things are together. (That just feels like the right thing to do
but so far, most of my "feelings" have been wrong!)
Once again, as I stated upthread some time ago and others have
reiterated, the common practice (but by no means the only one) is one
logger per class.
Right. That is gradually sinking in, believe it or not! In fact, I'm just
about ready to replace all of the existing nonsense that I've been doing
with a
Logger logger = Logger.getLogger(getClass().getName());
in all my classes.
Loggers "inherit", so that gives some flexibility in how you do
things.
What? You should only have one log, unless they use different
libraries to log.
No. I'm strictly using java.util.logging for now. Arved's got me thinking
about this new one, slf4j, but I'm not ready to go there yet.
So I want to end up with all of my classes in all of my Projects writing
to a single log?
Hmm. Yes, I suppose that makes sense. I need to review the whole
"inherit" aspect of logging but I've been thinking of one logger equating
to one log and that's not right, is it? See, the penny is dropping....
Lots of loggers but only one log.... Yes, I need to get my head around
that and think of how that works. Maybe rereading that logging overview
will make that sink in....
Huh? again.
What you name the logger is not connected to where it logs. Where it
logs is determined by the configuration for that logger. Usually it'll
write to the same log as its parent. The best practice here is to make
sense in the first place. You ask a question about naming a logger,
but cast it in turns of where it logs. Apples and oranges, dude.
Naming a logger doesn't change where it logs. Read the logger
documentation, please. All this information is in the documentation.
Yes, that's starting to become clear now.
The configuration determines where the log goes. No changes to logger
names are needed, just change the configuration file and restart.
We're starting to make the same points over and over again. It's
frustrating to provide you an answer and have you come back with the
same question. Please assimilate the answers already given.
I'm sure it is frustrating for you and I'm sorry. But believe me, it is
massively frustrating for me too!
To summarize the repeated points here:
- Configuration files usually suffice to configure logging. You rarely
need to programmatically configure logging, and should resist doing
so. Otherwise you defeat the point of changing logging strategy
without having to rebuild.
- The logger name determines which logger instance you get. NOT, and I
repeat, *NOT* where it logs.
- Conventionally, and usually most usefully, loggers are named for the
class in which they are used. So the logger for
'com.lewscanon.example.Foo' would come via
'getLogger(com.lewscanon.example.Foo.class.getName())'.
and emergingly,
- Packages are to organize your program irrespective of logging
strategy.
Some of this is material in the basic tutorial, particular the info
about packages, and should be mastered first before, say, learning how
to code a for-each loop.
Your commitment is duly noted and quite laudable.
But "starting" is still a long way from "hash ... the last bits out".
So I hope your patience is up to the task. You lack certain Java
fundamentals.
I think we're a lot closer to putting this to bed now than we were a few
hours ago. In fact, I may be able to proceed on my own now.
The only thing that REALLY bugs me still is that I can't find the darned
log records containing the weekdays that I mentioned elsewhere in the
thread. They're NOT at %h/java%u.log nor at the other place suggested in
the Tracing and Logging document. And THAT is really driving me crazy. I
can't think of anywhere else to look based on anything I've seen in the
references you and others have given me. I _think_ the logging.properties
file is ensuring that a physical log file is being written but maybe it's
messed up in some way to keep it from writing at all. Or from righting
INFO level records. But I don't think that's it.
If you have any insight into that, you'd really be helping me out. It's
hard to absorb the information you are giving me when my mind keeps
obsessing on where the darned log files are.