Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #12762

Re: Question about loggers

From Arved Sandstrom <asandstrom3minus1@eastlink.ca>
Newsgroups comp.lang.java.programmer
Subject Re: Question about loggers
References <XnsA00FACCA4B5E9jpnasty@94.75.214.39> <jj8qh3$ufb$1@dont-email.me> <4f57fb71$0$290$14726298@news.sunsite.dk>
Message-ID <RH%5r.41245$np3.6597@newsfe05.iad> (permalink)
Organization Public Usenet Newsgroup Access
Date 2012-03-08 06:18 -0400

Show all headers | View raw


On 12-03-07 08:21 PM, Arne Vajhøj wrote:
> On 3/7/2012 6:21 PM, markspace wrote:
>> On 3/7/2012 1:52 PM, Novice wrote:
>>> My impression from the "Aspect Questions" thread was that the "best
>>> practices" approach to logging was to use named loggers, where, in
>>> essence,
>>> each method that needs to write to the log creates a named logger via
>>>
>>> Logger logger = Logger.getLogger(getClass().getName());
>>
>>
>> I could see an app that was divided into functional parts, like maybe
>> "DATABASE" and "GUI", etc. where the logging was specified to use those
>> names:
>>
>> Logger log = Logger.getLogger( "GUI" );
>>
>> But while I could see this, I've never actually heard of anyone
>> specifying it. Loggers by class name is all I've ever seen.
> 
> That is generally accepted best practice.
> 
> And assuming that database or gui classses are all in a single
> package or a single subtree of packages, then one can managed
> them just fine via the full class name model.
> 
> Arne

I've mentioned a few times in the past some projects I've worked on
where we substantially changed the logging in a number of J2EE/Java EE
apps for a client. Improved I'd like to think, at least that's what the
ops support people for the client have opined for a few years now, and
that's what matters.

We did build in the ability to specify "functional parts" or "functional
areas", exactly like "DATABASE" or "GUI" (although in our case it was
quite a bit more discrete). But this was incorporated as part of the
message text (the %m part of log4j PatternLayout); it's not something
that log4j as a framework knows anything about. It's best thought of as
an informal, extra conversion specifier in PatternLayout. We also put in
authenticated userID in the same way.

I might add, enough [1] "functional parts" or subsystems in a JEE app
tend to crosscut Java packages that relying merely on the logging
framework and classname-specified loggers to reflect this usually
doesn't work. It's not so much for managing loggers that you might do
something like I describe, it's for the benefit of analyzing logs with
grep or Splunk or what have you. For managing loggers through the
framework config files it's still a matter of configuring loggers at
package or class level in the usual way, so "loggers by class name" is
absolutely the way to go still.

AHS

1. Just what it says. :-) Many, maybe most, functional subsystems in a
JEE app map rather cleanly to packages. Application/service layer
functional subsystems tend to do that. But a number of subsystems don't
always map cleanly to packages.
-- 
-- Gaiety is the most outstanding feature of the Soviet Union.
Josef Stalin, November 1935

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar


Thread

Question about loggers Novice <novice@example..com> - 2012-03-07 21:52 +0000
  Re: Question about loggers Arne Vajhøj <arne@vajhoej.dk> - 2012-03-07 17:16 -0500
    Re: Question about loggers Novice <novice@example..com> - 2012-03-07 23:57 +0000
      Re: Question about loggers Arne Vajhøj <arne@vajhoej.dk> - 2012-03-07 19:24 -0500
        Re: Question about loggers Lew <noone@lewscanon.com> - 2012-03-08 07:22 -0800
          Re: Question about loggers Arne Vajhøj <arne@vajhoej.dk> - 2012-03-08 10:27 -0500
            Re: Question about loggers Lew <lewbloch@gmail.com> - 2012-03-08 11:58 -0800
              Re: Question about loggers Arne Vajhøj <arne@vajhoej.dk> - 2012-03-08 15:49 -0500
          Re: Question about loggers Robert Klemme <shortcutter@googlemail.com> - 2012-03-08 08:15 -0800
            Re: Question about loggers markspace <-@.> - 2012-03-08 10:05 -0800
              Re: Question about loggers Arne Vajhøj <arne@vajhoej.dk> - 2012-03-08 13:50 -0500
              Re: Question about loggers Robert Klemme <shortcutter@googlemail.com> - 2012-03-09 07:11 -0800
                Re: Question about loggers Lew <noone@lewscanon.com> - 2012-03-09 07:45 -0800
                Re: Question about loggers markspace <-@.> - 2012-03-09 07:54 -0800
                Re: Question about loggers Arne Vajhøj <arne@vajhoej.dk> - 2012-03-09 11:03 -0500
                Re: Question about loggers markspace <-@.> - 2012-03-09 09:10 -0800
                Re: Question about loggers Arne Vajhøj <arne@vajhoej.dk> - 2012-03-09 12:27 -0500
                Re: Question about loggers Lew <lewbloch@gmail.com> - 2012-03-09 10:56 -0800
                Re: Question about loggers Robert Klemme <shortcutter@googlemail.com> - 2012-03-09 20:29 +0100
                Re: Question about loggers Arne Vajhøj <arne@vajhoej.dk> - 2012-03-09 11:04 -0500
                Re: Question about loggers markspace <-@.> - 2012-03-09 09:14 -0800
                Re: Question about loggers Arne Vajhøj <arne@vajhoej.dk> - 2012-03-09 12:22 -0500
                Re: Question about loggers Lew <lewbloch@gmail.com> - 2012-03-09 10:58 -0800
  Re: Question about loggers markspace <-@.> - 2012-03-07 15:21 -0800
    Re: Question about loggers Novice <novice@example..com> - 2012-03-08 00:01 +0000
    Re: Question about loggers Arne Vajhøj <arne@vajhoej.dk> - 2012-03-07 19:21 -0500
      Re: Question about loggers Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-08 06:18 -0400

csiph-web