sentence
stringlengths 1
1.38k
| label
stringclasses 3
values |
---|---|
(I should probably ask this as a separate Q.
|
o
|
) but how can I programmatical-ly turn off or change the threshold of a specific appender during runtime?
|
o
|
My old code: AsyncAppender appender
(AsyncAppender) LogManager.getRootLogger().getAppender("async");AppenderSkeleton mailAppender
(AppenderSkeleton) appender.getAppender("mail");.
|
o
|
NM I'll file separate question and for now look at: URL_http://mailman.qos.ch/pipermail/logback-user/2007-May/000209.html .
|
o
|
I could whip up some XSLT to translate log4j.xml to logback.xml.
|
o
|
The Log4J2 website reports that there is an adapter for SLF4J, so if you write your code to SLF4J you can switch to Log4J, Log4J2, and Logback whenever you want.
|
o
|
Here's the bridge: URL_http://logging.apache.org/log4j/2.x/log4j-slf4j - impl/.
|
o
|
It's a subjective question.
|
o
|
I'd suggest using slf4j, since it can use log4j as a backend if that's what you need.
|
o
|
You're likely to be using a number of components which may all use different logging APIs.
|
o
|
It's good to be able to consolidate the output via those APIs into a single output route.
|
p
|
Yes I think slf4j is what I'll go with.
|
o
|
I got confused between facade and impl.
|
n
|
Log4j 2.0 is not a facade and does not advertise to be one.
|
o
|
I would also recommend to use [jcabi-log]( URL_http://www.jcabi.com/jcabi-log /) as a convenient static wrapper of slf4j.
|
p
|
What's Up with Logging in Java?
|
o
|
Why one would use one of the following packages instead of the other?
|
o
|
Java Logging
Commons Logging
Log4j
SLF4j
Logback .
|
o
|
You might want to URL_http://stackoverflow.com/questions/873051 /, which compares SLF4j to Commons Logging.
|
o
|
Why the hell has Ceki created 3 logging frameworks!!!
|
o
|
thats madness...
|
o
|
@mP.
|
o
|
- log4j was the first, then disagreement arose, and slf4j+logback was written.
|
o
|
slf4j is the _API_ and logback the implementation of the API.
|
o
|
Regardless of everything else, slf4j is extremely useful.
|
o
|
For details on why Ceki Glc did create SLF4J+Logback see the following Devoxx talk: URL_http://www.parleys.com /#st=5&id=1701.
|
o
|
In chronological order of api apperance (as far as I know):
Log4j because most everybody uses it (in my experience)
Commons Logging because open source projects use it (so they can integrate with whatever logging framework is used in the integrated solution); especially valid if you're an API/Framework/OSS and you rely on other packages that use Commons Logging.
|
p
|
Commons Logging because you don't want to "lock down" to a particular logging framework (so instead you lock down to what Commons Logging gives you instead) - I don't think it is sensible to decide using this point as the reason.
|
p
|
Java logging because you don't want to add in an extra jar.
|
o
|
SLF4j because it's newer than Commons Logging and provides parameterized logging:
CODESNIPPET_JAVA1 .
|
o
|
Logback because it's newer than log4j and again, supports parameterized logging, as it implements SLF4j directly
SLF4j/Logback because it's written by the same guy who did log4j, so he's made it better (according to URL_http://stackoverflow.com/questions/354837/whats-up-with-logging-in-java#356038 [Ken-G] - thanks.
|
o
|
It seems to fit when looking at URL_http://www.slf4j.org/news.html [their-earlier-news-posts] )
SLF4j because they also publish a log4j adapter so you don't have to "switch out" log4j in older code - just make log4j.properties use SLF4j and it's configuration .
|
o
|
As far as I can tell the idea behind commons logging is that it should be used in libraries.
|
o
|
This way the library can always use the same logging framework (via commons logging) that the hosting application uses.
|
o
|
Thanks heaps to Loki for the question.
|
o
|
I now know that I'm not going to be using log4j as my default framework any more.
|
o
|
SLF4j FTW!Also thanks to Ken G for pointing out that SLF4j is written by the same guy as log4j.
|
o
|
The comment in your code example isn't 100% correct.The actual formatting of the message is performed lazily by Logback so it will only happen if the event is really handled by an appender
the appender requires the formatted message - which wouldn't happen in case of e.g.
|
o
|
an SocketAppender since the event is serialized using the unchanged message pattern + the arguments as Strings.I guess it just depends how you define "effectively" though.
|
o
|
It would certainly emit the same message (at least if entry and object are the same ;)) so please forgive my nitpicking.
|
o
|
SLF4J actually is just an API that sits on top of other logging frameworks.
|
o
|
Similar to the goal of Commons Logging, but more intuitive from my experience.
|
p
|
I find logging in Java to be confusing, inconsistent, poorly documented, and especially haphazard.
|
n
|
Moreover, there is a huge amount of similarity between these logging frameworks resulting in duplication of effort, and confusion as to what logging environment you are actually in.
|
n
|
In particular, if you are working in a serious Java web application stack, you are often in _multiple_ logging environments at one time; (e.g hibernate may use log4j, and tomcat java.util.logging).
|
p
|
Apache commons is meant to bridge different logging frameworks, but really just adds more complexity.
|
o
|
If you do not know this ahead of time, it is utterly bewildering.
|
n
|
Why are my log messages not printing out to the console, etc.?
|
o
|
Ohh because I am looking at the Tomcat logs, and not log4j.
|
o
|
Adding yet another layer of complexity, the application server may have global logging configurations that may not recognize local configurations for a particular web application.
|
o
|
Lastly, all these logging frameworks are WAY TOO COMPLICATED.
|
o
|
Logging in Java has been a disorganized mess leaving developers like me frustrated and confused.
|
n
|
Early versions of Java did not have a built-in logging framework leading to this scenario.
|
o
|
Is this an answer?
|
o
|
It looks more like a rant.
|
n
|
I am sorry.
|
n
|
It
a little bit of a rant.
|
n
|
But it is also a cogent response to "Whats Up with Logging in Java?".
|
p
|
The answer, in short, is it is deeply broken.
|
n
|
well it's not worth a -1 vote ;P But something to ponder about.
|
p
|
The problems started when Sun actually added java.util.logging to Java 1.4.
|
o
|
Before that LOG4J was well established and in wide use.
|
p
|
After that there was the necessity of wrappers to support both LOG4J and java.util.logging.
|
o
|
Also, since jul is contained in the java.
|
o
|
package, it can't be replaced by swapping a JAR - which is the way SLF4J bridges the other frameworks.
|
o
|
This was probably the worst Sun idea ever... and it ultimately led to the wrong assumption that a "good Java citizen" should use jul.
|
n
|
@Huxi, I maintain that the Calendar API was worse.
|
n
|
In defense of Sun it wasn't their code, but came from Taglient.
|
o
|
There's one important point that wasn't mentioned before: SLF4J (and both Logback and LOG4J as the logging backend) have support for a so called Mapped Diagnostic Context (MDC, see URL_http://slf4j.org/apidocs/org/slf4j/MDC.html [javadoc] and URL_http://logback.qos.ch/manual/mdc.html [documentation] ).
|
o
|
This is essentially a thread-local Map<String,Object> which you can use to add additional context information to your logging event.
|
o
|
The current state of the MDC is attached to every event.
|
o
|
This can be incredibly useful if you put stuff like the username and the URL of the request (in case of a webapp) into it.
|
o
|
This can be done automatically using a filter, for example.
|
o
|
Technically, it's a thread-local Map<string,string>.
|
o
|
See also answers to the question URL_http://stackoverflow.com/questions/296150 /what-are-the-best-practices-to-log-an-error [What-are-the-best-practices-to- log-an-error?
|
o
|
] , especially:
There are some potentialclassloading issues with CommonsLogging.
|
o
|
Log4J and SLF4J were developed by the same person, learning from issues found in practice with Log4J.
|
o
|
The URL_http://commons.apache.org/logging/ [Commons-Logging-overview] gives the reason for its existence: logging from library code, when you have no control over the underlying logging framework.
|
o
|
Very important for the various Apache projects, which will be linked into outside applications.
|
o
|
Perhaps not so important for internal IT projects, where you have complete control.
|
o
|
That said, I write to Commons Logging, as do many of the other developers I know.
|
o
|
The reason is to minimize mental baggage: you can change projects or jobs, and not have to learn a new framework (provided the new job/project also uses CL, and/or you can convince them to move to it).
|
o
|
Also, there is some value to creating your own wrappers around whatever framework you use.
|
o
|
As described URL_http://www.kdgregory.com/index.php?page=java.logging [here] , I like to use a LogWrapper object to provide custom stringification (important), and minimize the visual clutter of logging statements (less important).
|
o
|
There's also a commons.logging=>SLF4J bridge which can be used to route all CL logging over SLF4J.
|
o
|
SLF4J supports bridging of commons.logging, LOG4J and (a bit cumbersome, but as good as possible) java.util.logging so all logs will end up in whatever SLF4J backend you'll use.
|
n
|
See URL_http://slf4j.org/legacy.html I'd use Logback, btw, but you could argue that I'm biased.
|
o
|
In our company project we use LOG4j and it is very easy to use like Stephen showed in his example.We also have written our own pattern classes for LOG4j so you can create your own output file schemas.
|
p
|
You can describe how your log file should look like.
|
o
|
It is possible to enhance the original log4j classes.
|
o
|
All LOG4j properties you can change in a log4j.properties file, so you can use different files for different projects.
|
o
|
Java logging is not my favorit, but this could be because i use log4j from the beginning.
|
o
|
Generally I would default to using Log4J.
|
o
|
I would use Java Logging if I didn't mind a dependency on Java 1.4 but I would still use Log4J in preference.
|
o
|
I would use Commons Logging if I was enhancing something that already used it.
|
o
|
Didn't mind a dependency on 1.4??
|
o
|
Even 1.4 has hit its end of service life.
|
o
|
@TomHe means jdk1.4+ dont be silly.
|
n
|
Actually I've recently done some work in a system that was still running under jdk 1.3 :-(, and it was less than two years ago I was last maintaining a
1.2** system.
|
o
|
Too many places don't upgrade unless they absolutely have to, they just refuse to install the upgrades.
|
n
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.