Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the possible reasons behind "log4j: Error Could not find value for key log4j.appender.SQL_APPENDER"

I am wondering why I have this error when deploying my web application.

log4j: Error Could not find value for key log4j.appender.SQL_APPENDER

Here is my log4j.properties file.

log4j.rootLogger=error, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Print the date in ISO 8601 format
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=application.log

log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

log4j.logger.org.hibernate.SQL=DEBUG, SQL_APPENDER
log4j.additivity.org.hibernate.SQL=false

Do I have to do some configuration in the server side? I am running my application on a Tomcat 7 server. I added this dependency to the pom.xml file:

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.16</version>
</dependency>
like image 308
Rami Avatar asked Aug 10 '12 09:08

Rami


People also ask

What is the use of Appender in Log4j?

Log4j provides Appender objects which are primarily responsible for printing logging messages to different destinations such as console, files, NT event logs, Swing components, JMS, remote UNIX syslog daemons, sockets, etc.

What are the three most important components of Log4j?

Log4j has three main components: loggers, appenders, and layouts. These components work together to accomplish the following tasks: Record messages based on message type and level.

What is Log4j Appender console target?

Log4j2 ConsoleAppender appends the log events generated by application into the System. out or System. err . The default target is System.


2 Answers

You need to define log.appender.SQL_APPENDER, since you assign it in the line

 log4j.logger.org.hibernate.SQL=DEBUG, SQL_APPENDER

You are defining appender R but no SQL_APPENDER

like image 129
SJuan76 Avatar answered Sep 21 '22 13:09

SJuan76


As SJuan mentioned you need to define

log.appender.SQL_APPENDER

and that is done something like this :

log4j.appender.SQL_APPENDER=org.apache.log4j.RollingFileAppender

and might as well add these while you are at it...

log4j.appender.SQL_APPENDER.File=c:/EC_sql.log log4j.appender.SQL_APPENDER.MaxFileSize=1000KB log4j.appender.SQL_APPENDER.MaxBackupIndex=62 log4j.appender.SQL_APPENDER.layout=org.apache.log4j.PatternLayout log4j.appender.SQL_APPENDER.layout.ConversionPattern=[%d] %5p [%t] (%F:%L) - %m%n

Hope this helps someone!

like image 21
Wodash Avatar answered Sep 20 '22 13:09

Wodash