Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!216.40.30.109.MISMATCH!novia!posts.news.sonic.net!nnrp1.nntp.sonic.net!not-for-mail From: Kevin McMurtrie Newsgroups: comp.lang.java.programmer Subject: Re: dependency injection and loggers References: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) X-Face: #tdH+D1#njA1e^CLB^/(2]&X!c><$I]~!twG8kd3Ny41&5}K7Vyg"?Qs,G<{zMHK5h5@itD <+6=*QG@h3RactCyNsI2qChmy)Bl7)BlQPBND4,`9N|NaHykv%.u"Z\?S5^TZ="q568?wU.Aa"/n9} Ru\Cn'?7P@m.!dc}6Vp{Ua_NjHr\o7w?C^HC"u\'bU&9hI_SMAX|i8)};lfJF-wS~4cL{E8YI"U4$o _ Organization: Sonic.Net NNTP-Posting-Date: 04 Jan 2013 17:18:59 GMT NNTP-Posting-Host: 28936bf8.news.sonic.net X-Trace: DXC=[<7?m39^NZa?iMTMo^eSYUM44oUM@\@;k95Fb X-Complaints-To: abuse@sonic.net Xref: csiph.com comp.lang.java.programmer:20943 In article , markspace wrote: > On 1/4/2013 4:00 AM, Tomer wrote: > > I love the concept of dependency injection via ctor. it simplifies > > life and makes testing easy. what about logger? i usually instantiate > > it in private static logger = Logger.getLogger(myclass); however this > > is not dependency injection, should I pass the logger into each ctor? > > this would look wierd... so what to do about loggers and depedency > > injection? > > > I agree with you on both counts. Ctors are an excellent way of > implementing dependency injection, and static methods aren't. > > However loggers are more of an aspect than a dependency. Absent some > other framework (AOP, for example, or some sort of annotation > processing), good old frameworks and libraries solve this problem. Have > a look at Apache logging: > > I'd say that Java's own logger (java.util.logging) is worth a look too if you want modularity. It's easy to plug in custom formatters and handlers. You map logging paths to handlers during app initialization so no dependency injection is involved. My biggest peeve about most loggers is that they don't indent multi-line log entries nicely and they're sensitive to disk latency. It's not a problem when you plug in your own parts. You can also do fancy logging to remote archiving systems (JSON or XML over socket or REST, etc.) with little effort. http://docs.oracle.com/javase/6/docs/api/java/util/logging/package-summar y.html -- I will not see posts from Google because I must filter them as spam