This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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.
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...
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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) .