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>
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...
protected final Log logger = LogFactory.getLog(getClass());
SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
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
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");
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
SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand