configuration log4j axis1 No appenders could be find for logger - log4j

I try to deploy web service using axis1 and use in my web service class log4j logger as
private static final Logger logger = Logger.getLogger(MobileService.class
.getName());
logger.debug("Count nodes" + nodes.getLength());
My class has default package. And I use next log4j.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="HTML-APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${catalina.home}/webapps/axis/WEB-INF/classes/log.html" />
<param name="DatePattern" value="'.'yyyy-MM-dd-HH'.html'" />
<layout class="org.apache.log4j.HTMLLayout" />
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="ALL"/>
<param name="LevelMax" value="INFO"/>
</filter>
</appender>
</log4j:configuration>
Also I add in class path for deploying my app next
set CATALINA_HOME=C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0
set PATH_TO_LOG4J=C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\webapps\axis\WEB-INF\classes\log4j.xml
java -Dlog4j.info -Dlog4j.configuration="file:C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\webapps\axis\WEB-INF\classes\log4j.xml" -cp "%CATALINA_HOME%\webapps\axis\WEB-INF\lib\axis.jar;%CATALINA_HOME%\webapps\axis\WEB-INF\lib\jaxrpc.jar;%CATALINA_HOME%\webapps\axis\WEB-INF\lib\commons-logging-1.0.4.jar;%CATALINA_HOME%\webapps\axis\WEB-INF\lib\wsdl4j-1.5.1.jar;%CATALINA_HOME%\webapps\axis\WEB-INF\lib\commons-discovery-0.2.jar;%CATALINA_HOME%\webapps\axis\WEB-INF\lib\saaj.jar;%CATALINA_HOME%\common\lib\activation.jar;%CATALINA_HOME%\common\lib\mail.jar;%CATALINA_HOME%\webapps\axis\log4j-1.2.8.jar" org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService MobileService.wsdd
pause
But even -Dlog4j.info -Dlog4j.configuration= doesn't help me. I get error no appenders could be found for logger (org.apache.axis.i18n.projectresourcebundle).
Can you help me?

I think, you forgot to configure a logger. To configure the root logger, for example, place the following lines to the end of your log4j.xml file (before </log4j:configuration>):
<root>
<priority value ="debug" />
<appender-ref ref="HTML-APPENDER" />
</root>

Related

Control SQL logging level in Catalina.out

Our app runs on Tomcat 8 and Linux. We have log4j.xml shipped with the war that controls the level of logging for our applications logging. The log4j also defines logging levels for SQL.
In hibernate.cfg.xml, the "hibernate.show_sql" is set to true.
<property name="hibernate.show_sql">true</property>
In $CATALINA_BASE/conf/logging.properties
All references to ConsoleAppender:
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
Are removed, so nothing is sent to std out except for the SQL statements.
The: "hibernate.show_sql">true, sends all SQL statements being processed to catalina.out – please note that catalina.out is a file created only on Linux/Unix machines.
I read that "hibernate.show_sql">true, logs the SQL statements at DEBUG level. The problem is that I want to log those statements at ERROR level but don’t know how to control the level?
I read that that level for SQL logging can be controlled by log4j.xml, but changing it in log4j.xml has no effect on how the catalina.out is being logged. Does anyone know how can I control the SQL logging in catalina.out to be only at ERROR level?
Below is log4j.xml.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="mylog" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${catalina.base}/logs/mylog.log" />
<param name="Threshold" value="TRACE" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="300MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="it.openutils.log4j.FilteredPatternLayout">
<param name="ConversionPattern"
value="%d{ISO8601} %5p [%t] Executor:%X{Executor} Type:%X{Type} A:%X{Account} C:%X{Campaign} %c{1}:%L - %m%n" />
</layout>
</appender>
<logger name="org.hibernate.SQL" additivity="false">
<level value="ERROR" />
<appender-ref ref="mylog" />
</logger>
<logger name="org.hibernate">
<level value="ERROR"/>
</logger>
<logger name="org.hibernate.jdbc.JDBCContext">
<level value="ERROR"/>
</logger>
<root>
<level value="info" />
<appender-ref ref="mylog" />
</root>
Since I was not able to find anyway to set the level to ERROR for Catalina.out, I decided to turn off the SQL logging all together. So I changed all levels in log4j.xml back to INFO and set this property to false in hibernate.cfg.xml.
<property name="hibernate.show_sql">false</property>
After a while logging, I noticed that there is nothing being logged in Catalina.out unless an error happens, so in this case, the errors and exceptions are being logged into Catalina.out and not the regular SQL statements, which is (almost) something I was trying to achieve at the first place. I do not know why that’s the case thou and where/how those logging levels are defined. But hope that helps somebody.

Logging from my Java EE Application

I have a big Problem with my Logging. I have a the following strucure of my project:
MyApplication
ear
ejb
com.test.util (src/main/java)
Resources.java (Produce the Logger Instance)
Some Classe which use the Logger with #Inject
log4j.xml (src/main/resources)
web
Here's my Resources.java:
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Resources {
#Produces
#PersistenceContext
private EntityManager em;
#Produces
public Logger produceLog(InjectionPoint injectionPoint) {
return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}
}
And here is my log4j.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN"
"http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<!-- <appender-ref ref="CONSOLE"/> -->
<appender-ref ref="FILE" />
</appender>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-d: %-5p [%8c] - %m%n" />
</layout>
</appender>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${jboss.server.home.dir}/log/emember.log" />
<param name="MaxFileSize" value="10000KB" />
<param name="MaxBackupIndex" value="5" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-d: %-5p [%8c] - %m%n" />
</layout>
</appender>
<category name="org.hibernate.type">
<priority value="trace" />
</category>
<category name="org.hibernate.SQL">
<priority value="debug" />
</category>
<category name="org.hibernate.type.descriptor.sql.BasicBinder">
<priority value="trace" />
</category>
<category name="ch.test">
<priority value="debug" />
</category>
<root>
<priority value="INFO" />
<appender-ref ref="ASYNC" />
</root>
</log4j:configuration>
Whe i use my Unit-Test it work's fine, but when i deplay the ear-File then it doesn't use my log4j.xml. I use a JBoss AS 7 Application Server. And yes i've read all the tutorials with this title, but it doesn't work for me.
Can someone help me with this Problem?
You want to bootstrap SLF4j to be picked up by your EAR application as early as possible. Given you are using JBoss AS 7 as a Java EE 6 implementation, you can use EJB 3.1 singletons as follows:
#Singleton
#Startup
public class BootstrapLogging {
#PostConstruct
public void doUponConstruction() {
URL url = getClass().getClassLoader().getResource("log4j.xml");
DOMConfigurator.configure(url);
}
}
Another Qualifier to guarantee type safety to avoid possible ambiguity with JBoss Logger bean:
#Qualifier
#Retention(RUNTIME)
#Target({METHOD, FIELD, PARAMETER, TYPE})
public #interface SLF4jLogger {
}
Finally, you can inject the Logger using the following snippet:
#Inject #SLF4jLogger
private Logger LOG;
Please add a comment, in case you have a further inquiry. I will reply as soon as I can.
Is there a special reason you want to deploy your log4j.xml? This makes it hard to configure the logging at runtime. I would configure the logging in standalone.xml. If you do this to get application-specific logging, I would configure logging-profiles (>7.1/EAP6.1)
This might work if you exclude the servers logging dependencies and include in your deployment. You would need log4j, slf4j-api and the bindings for slf4j to log4j. I can't recall exactly how the slf4j static bindings work which if it doesn't work would be where the issue likely is.
For the exclusions in your jboss-deployment-structure.xml you'd need to exclude the modules org.slf4j, org.apache.log4j and possible org.apache.commons.logging.
IMO though logging should be configured on the server and not within a deployment. When configured within a deployment you lose things like runtime changes to the logging configuration. Say you want to enable debug logging for a specific category. If you use the server logging it will like work with a command/operation of some sort. If you use a configuration within your deployment you'd likely have to redeploy your application.

Log 4j Html Layout

I am using log4j (HTML Layout) the file does not get rolled over everyday for the below log4j.xml. I am using log4j extras. If I use log into a simple log file it works fine but does not work for a html layout.
<?xml version="1.0" encoding="windows-1252"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<!-- Daily Rolling File Appender that compresses old files -->
<appender name="file" class="org.apache.log4j.rolling.RollingFileAppender" >
<param name="threshold" value="info"/>
<rollingPolicy name="file" class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="${catalina.home}/ApplicationLogs/ApplicationLogs-%d{yyyy-mm-dd}.html"/>
<param name="ActiveFileName" value="${catalina.home}/ApplicationLogs/ApplicationLogs.html"/>
</rollingPolicy>
<layout class="org.apache.log4j.HTMLLayout" >
<param name="LocationInfo" value="true" />
</layout>
</appender>
<root>
<priority value="debug"></priority>
<appender-ref ref="file" />
</root>
</log4j:configuration>

settings in jboss-log4j.xml not taking effect

I have a war file that I deployed to JBOSS_HOME/server/default/deploy.
I add the following to the JBOSS_HOME/server/default/conf/jboss-log4j.xml
<appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
<param name="Threshold" value="INFO"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
I restarted the server,
But the logs are not writing under Server.log,
Logs are generating under boot.log (including my war deployment logs also) in the path JBOSS_HOME/server/default/logs/.
(Im running Jboss with JDK7 on linux.)
See root section, add <appender-ref ref="FILE"/>:
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<!--
Set the root logger priority via a system property. Note this is parsed by log4j,
so the full JBoss system property format is not supported; e.g.
setting a default via ${jboss.server.log.threshold:WARN} will not work.
-->
<priority value="${jboss.server.log.threshold}"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
Defining an appender is not enough in itself. You need to associate that appender with one or more loggers in the logger hierarchy. If you look at the other parts of the file, you'll see loggers defined which use the <appender-ref> element. This sends output from that logger to that appender.
If all you want to do is to send all logging to your new appender, then add <appender-ref> to the <root> element, which defines the root logger, e.g.
<root>
<!-- existing config in <root> -->
<appender-ref ref="FILE"/> <!-- reference to my new appender -->
</root>
See this tutorial at JavaLobby for more details.

log4j basic configuration

I used log4j to log some steps in my application. To be quick and dirty, I used:
org.apache.log4j.BasicConfigurator.configure();
This output my logs in the Eclipse console.
I want to know if and how to set the level threshold higher than DEBUG? In other word, I do not want to display DEBUG level message, just ERR, WARN, INFO.
Thank you.
EDIT:
May I use this following?
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
[...]
Logger logger = Logger.getLogger(this.class);
logger.setLevel(Level.INFO);
I think the simplest way would be:
Logger.getRootLogger().setLevel(Level.INFO);
org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.INFO);
Assuming you are calling BasicConfigurator.configure() before any loggers are called:
You can use either of these config files to change it without recompiling:
log4j.properties
log4j.rootLogger=INFO
log4j.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<root>
<priority value="INFO"/>
</root>
</log4j:configuration>
One of these must be on command line.
1) Find your appender, you sould have something like this in your log4j.xml configuration file.
<appender name="DEBUG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/logs/rmDebug.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="1500KB"/>
<param name="MaxBackupIndex" value="2"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="**FOOBAR** %d{dd.MM.yyyy HH:mm:ss} %c %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="DEBUG" />
<param name="LevelMax" value="FATAL" />
</filter>
</appender>
You see levelMin and LevelMax value ? levelMin is where you begin to log, and levelMax, where you stop to log. ( with this specific appender ). You can have several appender.
Then for assign this appender to a class or package. You can do something like that :
<category name="com.foobar.automation.doremiResourceManager" additivity="true">
<appender-ref ref="DEBUG"/>
</category>
If you are not configuring inside the properties file, use this:
Logger root = Logger.getRootLogger();
root.setLevel(Level.INFO);
root.addAppender(new ConsoleAppender(
new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)));
What BasicConfigurator.configure() do is adding root logger to a ConsoleAppender and set the appender layout to a PatternLayout with the pattern "%r [%t] %-5p %c - %m%n". So you need to set the root logger's level. If you only set the level of the logger of this class, the level of root logger is unchanged, then all the other loggers(except this class's) may still use root logger's level, so you will still see the unwanted logs.
See http://logging.apache.org/log4j/1.2/manual.html.

Resources