*
The moose likes Struts and the fly likes log4j implemetation 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 » Frameworks » Struts
Bookmark "log4j implemetation" Watch "log4j implemetation" New topic
Author

log4j implemetation

Raj Joe
Ranch Hand

Joined: Oct 15, 2004
Posts: 41
I have created a named logger(static) instance for each class.
I have created info ,debug,error etc as objects.

n the above scenerio if I have 400 classes then 400 static instances will be crated.
In each class I would have used lost of info,error etc ,so large number of these objects will be created for each class.

What I would like to know what is the advantage of creating info,error as objects than just call logDebug of the logger with string param.

I am afraid this will affect the performance of the system.
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
Raj I think a good inspiration for your work would be Log4j (the de facto standard for logging).

./pope


blog - InfoQ.com
Matt Raible
author
Ranch Hand

Joined: Jan 11, 2001
Posts: 114
Ali is right, log4j makes logging much easier. However, many open source projects use Commons Logging, which allows you to plug in your logging implementation (i.e. log4j, JDK 1.4 Logging) at deploy time.

I'd recommend putting a log variable in a base class for each package and just inheriting from that. Learn More...


Matt<br /> <br />Author: <a href="http://springlive.com" target="_blank" rel="nofollow">Spring Live</a> and <a href="http://www.apress.com/book/bookDisplay.html?bID=256" target="_blank" rel="nofollow">Pro JSP</a><br />Weblogs: <a href="http://raibledesigns.com" target="_blank" rel="nofollow">Raible Designs</a> <a href="http://jroller.com/page/raible" target="_blank" rel="nofollow">Spring Live Blog</a>
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Originally posted by Matt Raible:
Ali is right, log4j makes logging much easier. However, many open source projects use Commons Logging, which allows you to plug in your logging implementation (i.e. log4j, JDK 1.4 Logging) at deploy time.

I'd recommend putting a log variable in a base class for each package and just inheriting from that. Learn More...


I read in your link.

I have some question to tell you.


protected final Log logger = LogFactory.getLog(getClass());


When i used logger instance in subclass , i don't know name of subsclass Because in log file ,it's show baseclass's name only.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
Indeed. This technique is recommended for large hierachies/application. There you will need to log the module and not every particular class. Instead, in a smaller application you can use the simple way:



./pope
Raj Joe
Ranch Hand

Joined: Oct 15, 2004
Posts: 41
Originally posted by Ali Pope:
Indeed. This technique is recommended for large hierachies/application. There you will need to log the module and not every particular class. Instead, in a smaller application you can use the simple way:



./pope


Pope,

I am talking about usage of log4j.

1. Firstly What is the advantage of having named loggers for each class?

2. Secondly look at the statements below

logger.error(new Error("","",""));

Is creation of customize classes like new Error()/Debug/Info etc very expensive?how is it different from the below statement?

logger.logError("eror message");
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995

1. Firstly What is the advantage of having named loggers for each class?


Debugging, traceability and maybe audit


2. Secondly look at the statements below

logger.error(new Error("","",""));

Is creation of customize classes like new Error()/Debug/Info etc very expensive?how is it different from the below statement?

logger.logError("eror message");


I am not saying this is bad. Object creating costs are not so high - maybe just as regards the garbage collection (short living objects).
I am not an adept of re-inventing the wheel. Logging - even if it seems simple - may raise problems (concurrency, etc).

./pope
Raj Joe
Ranch Hand

Joined: Oct 15, 2004
Posts: 41
Originally posted by Ali Pope:


I am not saying this is bad. Object creating costs are not so high - maybe just as regards the garbage collection (short living objects).
I am not an adept of re-inventing the wheel. Logging - even if it seems simple - may raise problems (concurrency, etc).

./pope


thanks pope.
Concurrency - can you please expand on concurrency issue with respect to logging (log4J)
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
A logging framework can use as support the console, a file (multiple files), a remote file, a database etc.
So, considering that the logging framework will be used also in a multi-threaded application env you may face problems while sharing the resource access throught multiple threads (this is a very short :-) ).

./pope
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Concurrent of user is not mind in Logging solution because if your app have concurrent problem , you can use another solution to solve such as Load balancing, cloutering .. etc.
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
somkiat I am not talking about concurrent from the point of view of the client. In the aboves, the logger is seen as the service and the application as the client. The logger must be able to respond to concurrent requests from the client (from the application) .

./pope
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: log4j implemetation
 
Similar Threads
Good logging system for WebApp (Struts)
this and static don't mix
How to use log across objects
destroying objects
static variable and GC