Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pattern Used for log4j

 
Manisha sachin Patil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Can anyone please tell me what type of Java pattern does log4j follow?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not just one pattern. Design patterns are much more fine in granularity.

Why do you ask?
 
Manisha sachin Patil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ilja,
I was asked this question in one of the interviews...could you please tell me if it follows any design pattern(s)
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Nisha",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names get deleted.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Logger.getLogger(something in here) looks like some sort of builder pattern to me.
 
Manisha sachin Patil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello David,
thanks for the info about the format of name.I've updated my profile.Hope its fine now.
I did a google search and found on serverside that the
Logger.getLogger(something in here) follows some Aspect pattern.'am not sure what is aspect pattern.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thing you mean 'aspect oriented', as in Aspect Oriented Programming (AOP) opposed to Object Oriented, although the two aren't incompatible.
 
Manisha sachin Patil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not know what is aspect pattern.Just read came across it on the website.
In one of your previous replies you said "Logger.getLogger(something in here) looks like some sort of builder pattern to me."

I'm just curious to know how its a kinda builder pattern?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David O'Meara:
Logger.getLogger(something in here) looks like some sort of builder pattern to me.


Does it? I don't see it - especially since it's a single static method call. A build typically has a number of method calls on a builder object.
 
Manisha sachin Patil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didnt get any satisfactory answer yet to my query..can anyone please explain to me if the log4j follows any design patterns?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ilja: I was just trying to have something to say and start conversation

Nisha: It undoubtedly does. I'd have a look at the source and developer notes if I were you.
 
Nicolas Brasseur
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nisha,

at first sight I would say Strategy and Factory.

Strategy because using the Log4J getLogger() method hides the real implementation returned. The only thing you know is that it is a subclass of Logger.
Kind of Abstract Factory or Factory Method that hides the instantiation of the real object. You don't have to write any new keyword.

For the rest, you should have a look at the internals ...

Nicolas
 
Nicolas Brasseur
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way ...

I personally isolate the call to Logger.getLogger(String or Class) in to a static method in a helper class HelperLogger.getLogger() that does not take any argument.
In this method I use the Thread.currentThread().getStackTrace() that returns a StackTraceElement array. Using the StackTraceElement.getClassName() I retrieve the String to be passed to the Logger.getLogger(String) of Log4J.

The main advantage is that you can now cut&paste you LoggerHelper.getLogger() statements in all your classes without having to modify them.

Nicolas

[ May 29, 2008: Message edited by: Nicolas Brasseur ]
[ May 29, 2008: Message edited by: Nicolas Brasseur ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic