While printing mybatis SQL statements on console I am getting this error:
java.lang.NoSuchMethodError: org.apache.log4j.Logger.isTraceEnabled()Z
I use log4j which is supported by mybatis.
My log4j.properties file:
### Global logging configuration
log4j.rootLogger=INFO, stdout
log4j.logger.com.app.mybatis.dao=stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
Strange thing is that if I specify a class to be logged, for example
log4j.logger.com.app.mybatis.dao.MyClass=stdout
it works fine but not for the package. Any idea of what would be causing this?
You need to upgrade the log4j to the version 1.2.12+
The method org.apache.log4j.Logger.isTraceEnabled(), including org.apache.log4j.Level.TRACE was added since version 1.2.12
* Currently, the latest version is 1.2.17
I solved the problem by using
org.apache.ibatis.logging.LogFactory.useCustomLogging
method and giving a parameter as a custom logging class that extends Log4jImpl class. I overrode isTraceEnabled method. So error giving method would not be called anymore.
Related
I am using web-based application along with Log4J API for logging purpose.
In Log4J, I am using DailyRollingFileAppender to create a new log file for logging on each day.
here is my log4j properties file configuration
log4j.logger.org.apache.cxf=ERROR
log4j.rootLogger=INFO, jtiServiceAppender
log4j.appender.jtiServiceAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.jtiServiceAppender.File=${catalina.home}/logs/jti/ilume-mw${logfilename}-app.log
log4j.appender.jtiServiceAppender.DatePattern='.'yyyy-MM-dd
log4j.appender.jtiServiceAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.jtiServiceAppender.layout.ConversionPattern=%d{dd.MM.yyyy HH\:mm\:ss} %-5p %t [%C{1}]\: %m%n
Problem:
In my case, the log files are not created for each day. For the same when I checked my tomcat server log I have observed that I am getting an error as
log4j:ERROR Failed to rename [D:\ilume-mwtmp0-app.log] to
[D:\ilume-mwtmp0-app.log.2019-07-09].
I have also referred the below link however still, I did not find a proper solution to my case.
Link : enter link description here
Any help or suggestion to solve this logging problem will be highly appreciated as it's been a couple of days and I am still not able to get any proper solution to this problem.
When adding appender-ref in logger tag, it throws renaming error. When adding appender-ref in root tag, it never throws that error.
Above is from below link. It seems same error and might help.
log4j:ERROR Failed to rename
Other than above, please check if there is permission issue at the directory where file needs to be renamed.
I have implemented JCS in my J2ee application which uses log4j for logging.
My Requirement
Set the application rootLogger in DEBUG level and jcs logs in ERROR mode.
What is tried
Tried the following in log4j properties
log4j.category.org.apache.common.jcs=ERROR
log4j.logger.org.apache.common.jcs=ERROR
But nothing is affecting the logging.
Whenever the cache access happens, it logs a bunch of returning first node messages.
Note : I am using the latest JCS commons-jcs-core-2.0-beta-1.jar
This is my complete log4j.properties
log4j.rootLogger=DEBUG, A1
# Use Console Appender for development
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern= %d [%t] %-5p - %m%n
log4j.logger.net.sf.jasperreports=ERROR
log4j.category.org.apache.common.jcs=ERROR
I missed an "s" in commons. Correcting it solved my problem.
Solution
Both the below statements can be used to configure JCS log level in log4j.
log4j.category.org.apache.commons.jcs=ERROR
log4j.logger.org.apache.commons.jcs=ERROR
JCS has a dependency on commons-logging for logging, and not log4j. Hence, log4j configurations won't matter unless you redirect commons-logging to log4j. To do that, create a file named commons-logging.properties and add the following in that.
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4jLogger
Recently I inherited a project and having some hard time configuring the logging in the sense I can't seem to configure it at all!
So let me first give you the context:
It runs under Jetty 9.2
It uses the Apache Commons logging library
It has a Maven dependency on log4j which I assume the apache commons will pick that up and use it.
There are no existing commons-logging.properties or log4j.properties so I assume it falls back to defaults.
There is no jetty-logging.properties either.
So here is my problem, it currently does not log the timestamp, the output is like this:
5027 [main] INFO org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/css/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
and:
912562 [qtp760972690-15] DEBUG com.xxx.xx.Class - Some Action Log Msg
No idea what those fields before the DEBUG are. I had previously worked with Tomcat, sl4j and pretty sure Apache Commons logging too.
So I thought I would config files both 'commons-logging.properties' and 'log4j.properties' in the WAR file WEB-INF/classes.
Now it recognises and picks up the 'commons-logging.properties' but the 'log4j.properities' seems to have no effect at all.
So am I missing a step here, have I forgotten something? Is this a Jetty issue because it uses sl4j and I'm not?
Here is is m commons-logging.properties:
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
log4j.configuration=log4j.properties
And here is my log4j.properties:
# Set root logger level to DEBUG.
log4j.rootLogger=DEBUG,stdout
# stdout is set to be a ConsoleAppender.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
# stdout uses PatternLayout.
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
Another note is that log lines from Jetty itself do have the nice date-stamp I want:
2014-09-06 19:36:19.356:INFO:/:main: Initializing Spring FrameworkServlet 'appServlet'
But not my main application logging.
I tried to run easy program with hibernate and HSQLDB.
I'm using log4j for this project with log4j.properties:
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %c{1}:%L - %m%n
# Root logger option
log4j.rootLogger=INFO, stdout
# Hibernate logging options (INFO only shows startup messages)
log4j.logger.org.hibernate=INFO
# Log JDBC bind parameter runtime arguments
log4j.logger.org.hibernate.type=INFO
and all is build with Ant, build file you can see here.
But when I run schemaexport target I caught next error:
BUILD FAILED
/home/nazar_art/workspace/Persistance/build.xml:64: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
But I hasn't use slf4j why this caused?
here is my content of lib folder with all jars that It uses:
I couldn't figure out why does this happen?
Here is better project structure:
EDIT:
I added slf4j-api-1.6.1.jar and slf4j-log4j12-1.6.1.jar but it throws:
BUILD FAILED
/home/nazar_art/workspace/Persistance/build.xml:64:
java.lang.NoClassDefFoundError: javax/persistence/EntityListeners
you can see here how it looks:
How to solve this trouble?
Hibernate uses SLF4J internally to do its own logging. It is an abstraction layer on top of different logging implementations. Frameworks like using this facade because in this case you still stay independend from certain implementations. You can also make it work with log4j. Follow this tutorial to make it work together.
Hibernate internally uses SLF4J for logging. Read the setup instructions here: http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#tutorial-firstapp-setup You need to keep SLF4J jar on the build and runtime classpath.
Hi I'm using log4j api for logging purpose. When I use the following code to append to the appender, it's showing "addAppender() is undefined for the type Logger" error
FileAppender myAppender = new FileAppender(new PatternLayout(),"output.log");
Logger.getLogger(ConfigFileReader.class.getName()).addAppender(myAppender);
Can anyone tell me what should I do to debug this error?
Are you sure that you are importing the correct Logger class? A common error is to import java.util.Logger instead of the Logger from the log4j package.