I'm sure this is easy, but I'm failing to find it.
I have a org.apache.commons.logging.Log instance for logging, and I see that the source code of one of my dependencies has statements like:
if (logger.isDebugEnabled())
logger.debug("Doing stuff.");
I would like to enable debugging, so that I could see these messages. I'm using Maven to build, and run tests. I don't particularly care whether the solution is a command-line argument, adding something to pom.xml, or using code to set the logger itself.
In your log4j.properties specify log4j.logger.com.yourpackage=debug. If you don't have a log4j.properties, get a default one (google it) and place it on the root of your classpath.
(commons-logging will delegate to log4j)
org.apache.commons.logging.Log is not a logging framework. It is an abstract interface which helps you to have any concrete logging implementation under it.
There is a good chance that you are using log4j underneath the org.apache.commons.logging.Log api . If that is the case then place a log4j.properties at the root of your classpath. If you already have one then you just need to change the log level as specified in the file .
If you are using any other logger like jdk logger you need to find the logging configuration file for the same.
Related
I am getting the following error:
ERROR StatusLogger Log4j2 could not find a logging implementation.
Please add log4j-core to the classpath. Using SimpleLogger to log to
the console.
I am using eclipse V4.3.2 in a GWT application.
Both log4j-api-2.4.1.jar and log4j-core-2.4.1.jar are on the class path.
I've seen other postings similar to my error but it's not clear to me what I am doing wrong if anything.
Thanks
Classpath is not enough (and actually wrong), you need server code within the WAR's WEB-INF (WEB-INF/lib to be exact here).
I have configuration the logback with specified custom logback.xml file, but the log it prints is not what I want.
This is my code to initial logback:
private void initLogBack() throws JoranException {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(createLogbackContext());
configurator.doConfigure(mycustomLogbackConf);
}
I think it may read some unexpected "logback.xml" files from somewhere I don't know. Is there any way to print all the configuration information that logback used?
e.g.
The configuration files it uses
The loggers defined
The debug levels defined
Is it possible?
logback 1.0.4 version has a fix with which you can set debug level at jvm level by using a property
-Dlogback.debug=true
Reference: http://jira.qos.ch/browse/LOGBACK-527
Hope it helps.
Can anyone tell me the difference between slf4j-log4j and log4j-over-slf4j? Which is more standard to use in a Java web application? I currently have both on the classpath and that is causing a runtime exception as the web server is trying to prevent a StackOverFlowException from happening.
Exception:
java.lang.IllegalStateException:
Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path
slf4j-log4j is using log4j as an implementation of slf4j.
log4j-over-slf4j causes calls to the log4j API to be 'routed' to slf4j.
You cannot use both of these JAR's at the same time.
Both are valid libraries to use and are equally 'standard', it depends on the project.
In general, if your project is using log4j already and you don't have the ability to update all of your log4j Loggers to slf4j Loggers; log4j-over-slf4j is a quick fix to be able to start using slf4j immediately.
However, if your project is new or does not have an existing logging mechanism and you choose to use slf4j, slf4j-log4j would be the way to go as it is just specifying slf4j should be bound to log4j.
That being said, I agree with c12's comment. Stop using log4j and instead use slf4j and logback.
in my project , org.slf4j.impl.Log4jLoggerFactory is in
activemq-all-5.7.0.jar
not in slf4j-log4j12.jar
the exception message mislead me
in one of my elicpse project I have come across this logger related snippet, I noticed that it is from slf4j library.
private static final Logger logger = LoggerFactory
.getLogger(someclass.class);
Then in some point of the code i noticed this,
logger.debug("Found {} object",
numberofobject);
My question is, when I run the program I do not see the logger output, how can I see that in eclipse?
You need to properly configure the binding for slf4j. slf4j is just a facade, not a logging tool.
Since 1.6.0 if no binding is found on the class path, then SLF4J will default to a no-operation implementation.
Have a look at the officiel manual here on how to configure slf4j.
you need to add a logging library to your project that implements the slf (just as Burkhard mentioned)
You need to configure the logger of your choice to log debug messages to the console (e.g. with a console appender in log4j)
I have a project which depends on hadoop-core.
hadoop-core has its own log4j configuration.
The default log4j configuration is loaded in my project.
I want my project not to be affected by it.
How do I solve this?
If you do not want the hadoop-core provided log4j configuration to be the one used by log4j you have to provide another configuration file that should be used.
You should have a look at the log4j manual. The section "Default Initialization Procedure" describes how log4j will try to find the initialization file and explains possibilities to match a special configuration (e.g. by setting the system property log4j.configuration).