Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log4j implemetation

 
Raj Joe
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raj I think a good inspiration for your work would be Log4j (the de facto standard for logging).

./pope
 
Matt Raible
author
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic