tag:blogger.com,1999:blog-8712770457197348465.post7266485339346620554..comments2024-03-19T05:51:39.935-07:00Comments on Javarevisited: Why use SLF4J over Log4J for logging in Java? Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger29125tag:blogger.com,1999:blog-8712770457197348465.post-48564416577830860522021-04-27T07:40:48.149-07:002021-04-27T07:40:48.149-07:00In 2021, I don't think this recommendation sti...In 2021, I don't think this recommendation still holds as SLF4J seems to be dormant: PR/issues/improvements are neglected and the 1.8/2.0 versions will remain forever in alpha/beta phase. In the meantime, Log4j2 is very active and can be also be used as a facade since they split API and core implementation.Unknownhttps://www.blogger.com/profile/01551140872112957579noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-31291256961250532012020-12-27T20:40:15.543-08:002020-12-27T20:40:15.543-08:00Hello Anonymous, Yes, I use twitter, @javinpaul, y...Hello Anonymous, Yes, I use twitter, @javinpaul, you can follow me there and thanks for kind words. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-20453057965658730722020-12-27T16:52:04.163-08:002020-12-27T16:52:04.163-08:00Hi there! Do you use Twitter? I'd like to foll...Hi there! Do you use Twitter? I'd like to follow you if that would be okay.<br />I'm absolutely enjoying your blog and look forward to new updates.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-31105483695357828482020-11-30T20:32:01.208-08:002020-11-30T20:32:01.208-08:00Thank you Anonymous, I appreciate your support. Thank you Anonymous, I appreciate your support. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-54496626892640151472020-11-29T23:04:03.181-08:002020-11-29T23:04:03.181-08:00I was able to find good advice from your blog post...I was able to find good advice from your blog posts.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-41810017770792098522016-12-09T06:27:10.790-08:002016-12-09T06:27:10.790-08:00@phansson, JUL is not great on performance - http:...@phansson, JUL is not great on performance - http://blog.takipi.com/the-logging-olympics-a-race-between-todays-top-5-logging-frameworks/<br /><br />Keep in mind that log4j was a dead project. So Ceki Gülcü (log4j creator) decided (perhaps due to apache politics) to create slf4j and logback as alternatives. But, things keep changing. Apache team (with new members) wake up and decide to rewrite Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-85360384263167018922016-08-19T12:35:39.915-07:002016-08-19T12:35:39.915-07:00My two cents: These days the benefits of using a l...My two cents: These days the benefits of using a logging framework different from JUL are really not enough to justify going outside the JDK. You compare to ancient Log4J and then say: "look, SLF4J is better" but you could have achieved the same with JUL. Correct me if wrong.phanssonhttps://www.blogger.com/profile/00537443592849480340noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-10864289707375301802016-07-07T05:35:50.982-07:002016-07-07T05:35:50.982-07:00Nice article, I been using SLF4J from last two yea...Nice article, I been using SLF4J from last two years but not aware about such benefits. Thanks.Sanjayhttps://www.blogger.com/profile/10350371035402604559noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-63027499732363101142016-02-29T06:43:48.995-08:002016-02-29T06:43:48.995-08:00I'm getting this warning in log:
log4j:WARN N...I'm getting this warning in log:<br /><br />log4j:WARN No appenders could be found for logger (org.apache.axiom.om.util.StAXUtils). <br />log4j:WARN Please initialize the log4j system properly. <br /><br />I've done some reasearch on the Internet, but i have no log4j.propesties file.<br />Using slf4j-api-1.7.12.jar<br /><br />Tanks a lot!<br />LUPUhttps://www.blogger.com/profile/13791515010000835596noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-42992008576324083922015-12-10T06:28:39.270-08:002015-12-10T06:28:39.270-08:00Thats a great blog. The knowledge on saving cpu ti...Thats a great blog. The knowledge on saving cpu time by avoiding string concatenation was something new for me.Anonymoushttps://www.blogger.com/profile/06040375397067413377noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-9316932810959852682015-05-06T14:31:15.089-07:002015-05-06T14:31:15.089-07:00Its a choice between efficient code and pretty cod...Its a choice between efficient code and pretty code. <br />Good compiler save the day by compiling a pretty looking code to an efficient oneAnonymoushttps://www.blogger.com/profile/14183559146738707229noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-60982161114241543152014-10-10T02:53:51.646-07:002014-10-10T02:53:51.646-07:00Something the isDebugEnabled check does in log4j i...Something the isDebugEnabled check does in log4j is save from the method call which includes creation of the String (argument of the method). So basically there will be no method call for log.debug if the debug is not enabled.<br />But if using slf4j we use the construct without any if check then the method call is happening and so is the String creation being done.<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-65780981095560195682014-02-11T00:55:31.922-08:002014-02-11T00:55:31.922-08:00
org.slf4j
slf4j-api
1.6.1
provided
org.s...<br /> org.slf4j<br /> slf4j-api<br /> 1.6.1<br /> provided<br /><br /><br /><br /> org.slf4j<br /> slf4j-log4j12<br /> 1.6.1<br /> provided<br /><br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-36983702451775585412014-02-03T07:50:27.355-08:002014-02-03T07:50:27.355-08:00When using the following with debug logging turned...When using the following with debug logging turned off<br /><br />logger.debug("Message {}, {}, {}", new Object[]{obj1,obj2,obj3});<br /><br />instead of <br /><br />if(logger.isDebugEnabled()) {<br /> logger.debug();<br />}<br /><br />are you not still creating objects unnecessarily? Isn't the message string itself and the new object array created unnecessarily?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-68447505827069606332014-02-03T00:11:01.725-08:002014-02-03T00:11:01.725-08:00God comparison between Log4j and SLF4j, but I thin...God comparison between Log4j and SLF4j, but I think you forgot to mention one of the key property of SLF4j library. In order to make your library using SLF4j, you only need a single mandatory dependency, namely slf4j-api.jar. If no binding is found on the class path, then SLF4J will default to a no-operation implementation, but your client might cry while finding right set of JAR for Log4j or Kapil Ahujanoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-22354641564065999432014-02-03T00:07:58.092-08:002014-02-03T00:07:58.092-08:00@Teong, each string literal is a String object, wh...@Teong, each string literal is a String object, which is created inside pool. StringBuilder is only used for string concatenation, for example in above case, two String object will be created in pool for two String literals " Creating process with id" and "for processing ", and one StringBuilder to generate final string. I hope this helps.Kapil Ahujanoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-11232941550322656282013-10-20T19:39:52.414-07:002013-10-20T19:39:52.414-07:00Hi,
Just kind of get confused when you mentioned ...Hi,<br /><br />Just kind of get confused when you mentioned that string concatenation actually creates string in string pool. I thought for statements like <br /><br /> " Creating process with id " + id +"for processing "+process<br /><br />Actually uses StringBuilder in the backend . So why is it created in the StringPool?<br /><br />thanksAnonymoushttps://www.blogger.com/profile/17050221411989802458noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-90548063754561464302013-10-01T21:38:59.375-07:002013-10-01T21:38:59.375-07:00Just keep in mind to use right set of SLF4j JAR wi...Just keep in mind to use right set of SLF4j JAR with any particular logging framework, for example , slf4j-log4j12.jar and log4j-1.3.x.jar will not work together even though both of them are from Log4j, one is connector for Log4j 1.2 while other is log4j 1.3.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-49770219601754112602013-08-29T11:49:42.030-07:002013-08-29T11:49:42.030-07:00Good day! I just wish to give a huge thumbs up for...Good day! I just wish to give a huge thumbs up for the nice information you have right here on this <br />post. I can be coming again to your blog for more soon.<br /><br /><br /><br />Also visit my web site; http://technologiesleader.blogspot.in/<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-42904801035373827312013-08-26T00:45:05.906-07:002013-08-26T00:45:05.906-07:00I think the maven dependencies that you put are wr...I think the maven dependencies that you put are wrong, they are duplicated twice. Can you check / fix? Musikelehttps://www.blogger.com/profile/15838743607580217968noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-32693147667860490282013-08-25T16:11:56.138-07:002013-08-25T16:11:56.138-07:00Javin,
Could you also write a blog post about Log...Javin,<br /><br />Could you also write a blog post about Log4j 2.0 (<a href="http://logging.apache.org/log4j/2.x/" rel="nofollow">http://logging.apache.org/log4j/2.x/</a>)? <br /><br />It has the same API that you mention, and it has some interesting performance improvements (like 12x more throughput in multi-threaded scenarios, and orders of magnitude(!) lower latency).Anonymoushttps://www.blogger.com/profile/07784933209710841050noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-77192558498620236972013-08-23T20:36:26.071-07:002013-08-23T20:36:26.071-07:00In java.util.logging I perform
logger.log(Level....In java.util.logging I perform <br /><br />logger.log(Level.FINE, "client with id {0} identified as node ord {1}", new Object[]{id, nodeOrd});<br /><br />is the option you mentioned "logger.debug("Processing trade with id: {} and symbol : {} ", id, symbol);" <br />better than the java.util.log wayPrashanthnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-48812026183893150972013-08-23T08:27:11.319-07:002013-08-23T08:27:11.319-07:00Hi, I've seen sl4fj for sometime now but never...Hi, I've seen sl4fj for sometime now but never had a good reason to put it in until i read your article; i personally didn't care about the facade benefits, but the string formatting benefits as well as the implied debug conditional checks etc. make it worth it!<br /><br />Nice, small article that was easy to read and converted me.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-26023359950141625492013-08-22T21:10:35.747-07:002013-08-22T21:10:35.747-07:00I think biggest advantage of using SLF4J over Log4...I think biggest advantage of using SLF4J over Log4J is better API. By the way, when using SLF4j, do you need to provide configuration file for both log4j and slf4j or only one?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-78089546867737153762013-08-22T18:56:27.088-07:002013-08-22T18:56:27.088-07:00Check SLF4J in combination with Logback instead of...Check SLF4J in combination with Logback instead of Log4J too.Prashanthnoreply@blogger.com