wood burning stoves 2.0*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Pattern Used for log4j Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Pattern Used for log4j" Watch "Pattern Used for log4j" New topic
Author

Pattern Used for log4j

Manisha sachin Patil
Greenhorn

Joined: May 19, 2008
Posts: 15
Hello,
Can anyone please tell me what type of Java pattern does log4j follow?


Regards,
Manisha
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
It's not just one pattern. Design patterns are much more fine in granularity.

Why do you ask?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Manisha sachin Patil
Greenhorn

Joined: May 19, 2008
Posts: 15
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

Joined: Mar 06, 2001
Posts: 13459

"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

Joined: Mar 06, 2001
Posts: 13459

Logger.getLogger(something in here) looks like some sort of builder pattern to me.
Manisha sachin Patil
Greenhorn

Joined: May 19, 2008
Posts: 15
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: May 19, 2008
Posts: 15
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

Joined: Jul 11, 2001
Posts: 14112
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

Joined: May 19, 2008
Posts: 15
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Nov 09, 2001
Posts: 45
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


<a href="http://www.javablackbelt.com/?utm_source=javaranch&utm_medium=signature&utm_campaign=Forum%2BBuzz" target="_blank" rel="nofollow">BlackBeltFactory Communtiy</a> founder - Building better developers<br /><b>Free</b> courses and mock exams
Nicolas Brasseur
Ranch Hand

Joined: Nov 09, 2001
Posts: 45
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pattern Used for log4j
 
Similar Threads
Singleton implementation in loggig / log4j
How do I configure the Log4j to tell me which method i am accessing in Java
how to log errors occurred in backend java engine or servlet
Debugging Best Practices??
error when i run log file