I tried to run simple example(Hello wold) in struts-2.3.4.1 with tomcat server 7.0.
But when i run this sample application i got following exception :
java.lang.NullPointerException
org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:501)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:432)
used Log4j.xml Configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender class="org.apache.log4j.rolling.RollingFileAppender" name="FixedWindowRollingFile">
<param name="Append" value="true"/>
<param name="ImmediateFlush" value="true"/>
<rollingPolicy class="org.apache.log4j.rolling.FixedWindowRollingPolicy">
<param name="fileNamePattern" value="c:/logs/HelloExample/HelloExample.%i.log"/>
<param name="minIndex" value="1"/>
<param name="maxIndex" value="10"/>
</rollingPolicy>
<triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
<param name="MaxFileSize" value="1002400"/>
</triggeringPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %p %c{1}:%L - %m%n"/>
</layout>
</appender>
<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.SimpleLayout"/>
</appender>
<root>
<priority value="DEBUG"/>
<appender-ref ref="ConsoleAppender"/>
<appender-ref ref="FixedWindowRollingFile"/>
</root>
</log4j:configuration>
Also I have used my own log4j.xml configuration file to configure web application but i got this exception regularly(generated log file https://gist.github.com/3851738).
Related
1)I want to generate the log file on daily basis using log4j2.xml. I am using the RollingFile appender tag to achieve the same.However, it is appending the logs on the same file.
<RollingFile name="FrameworkAppender" filePattern="${jboss.server.home.dir}/xyz_app-%d{yyyy-MM-dd}-%i.log" >
<PatternLayout>
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</PatternLayout>
<LevelRangeFilter minLevel="ERROR" maxLevel="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
<Policies>
<CronTriggeringPolicy schedule="0 0 0 * * ?" />
<SizeBasedTriggeringPolicy size="250 MB" />
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
2)Below is the category tag we have used in log4j.xml ,i want to know what is the equivalent of category tag in log4j2.xml ?
<category name="biz.theXYZ" additivity="false">
<level value="INFO" />
<appender-ref ref="FrameworkAppender" />
<appender-ref ref="ConsoleAppender" />
</category>
3)How to define SNMPTrapAppender with all the properties in log4j2?
<appender name="TRAP_LOG_APPENDER" class="org.apache.log4j.ext.SNMPTrapAppender">
<param name="ImplementationClassName" value="org.apache.log4j.ext.JoeSNMPTrapSender"/>
<param name="EnterpriseOID" value="1.3.6.1.4.1.2854.1"/>
<param name="ApplicationTrapOID" value="1.3.6.1.4.1.24.12.10.22.64"/>
<param name="ManagementHost" value="127.0.0.1"/>
<param name="ManagementHostTrapListenPort" value="162"/>
<param name="LocalIPAddress" value="127.0.0.1"/>
<param name="LocalTrapSendPort" value="161"/>
<param name="GenericTrapType" value="6"/>
<param name="SpecificTrapType" value="12345678"/>
<param name="CommunityString" value="public"/>
<param name="ForwardStackTraceWithTrap" value="true"/>
<param name="Threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d,%p,[%t],[%c],%m%n"/>
</layout>
</appender>
you should add
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
For the second question, the equivalent in log4j2 is:
<Loggers>
<Logger name="biz.theXYZ" level="info">
<AppenderRef ref="FrameworkAppender"/>
<AppenderRef ref="ConsoleAppender"/>
</Logger>
</Loggers>
Make sure to include the FrameworkAppender and ConsoleAppender in the Appenders section of your log4j2 file.
Having problem with integrating OpenJPA with log4j2.
OpenJPA + log4j worked fined
<appender name="OPENJPA_LOG" class="org.apache.log4j.RollingFileAppender">
<param name="maxFileSize" value="5MB" />
<param name="maxBackupIndex" value="10" />
<param name="file" value="./logs/openjpa.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c:%L - %m%n" />
</layout>
</appender>
<logger name="openjpa.jdbc.SQL" additivity="false">
<level value="TRACE" />
<appender-ref ref="OPENJPA_LOG" />
</logger>
But it is not working with log4j2.
<RollingFile name="OPENJPA_LOG" fileName="./logs/openjpa.log"
append="true" filePattern="./logs/openjpa.%i.log.gz"
ignoreExceptions="false">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} - %c [%thread] - %m%n</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10MB" />
</Policies>
<DefaultRolloverStrategy max="5" />
</RollingFile>
<Logger name="openjpa.jdbc.SQL" level="TRACE" additivity="false" >
<AppenderRef ref="OPENJPA_LOG" />
</Logger>
How to fix it.
If you still have issues with this you have to double check that in the persistence.xml you set <property name="openjpa.Log" value="slf4j"/>.
Indeed open jpa is not compatible with log4j2 natively so if you use <property name="openjpa.Log" value="log4j"/> you will run into a java.lang.ClassNotFoundException: org.apache.log4j.Priority.
Once openjpa logs are route properly to slf4j it is ok. I hope your application use sllf4j.
Be sure to use proper versions of log4j2 slf4j and bridge and remove all previous log4j1.x and old slf4j dependencies.
I am using log4j2
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
and a very basic configuration xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
</layout>
</appender>
<category name="org.apache.log4j.xml">
<priority value="info" />
</category>
<Root>
<priority value ="debug" />
<appender-ref ref="STDOUT" />
</Root>
</log4j:configuration>
For some reason logging is not working. I am getting
ERROR StatusLogger Error parsing /home/sfalk/workspace/java/lazy-model-access/lamoa-parent/lamoa-server/target/classes/log4j2.xml
ERROR StatusLogger No logging configuration
What am I doing wrong here?
Your configuration file is for log4j 1.x, not 2.5
I have a simple Netbeans 7.1.2 (NON MAVEN) project that use glassfish 3.1 server for testing.
I created a log4j2.xml file and placed it on the classpath
here it is
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="debug"/>
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} [%t] %-5p %c{1} - %m%n"/>
</layout>
</appender>
<appender name="rolling-file" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="c:\tmp\Program-Name.log"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="4"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %l - %m%n"/>
</layout>
</appender>
<logger name="org.hibernate">
<level value="info" />
</logger>
<root>
<priority value ="debug" />
<appender-ref ref="console" />
<appender-ref ref="rolling-file" />
</root>
</log4j:configuration>
the project uses hibernate to store data from a web service to a database.
However I am not able to log anything. I can see the logs of hibernate into the Netbeans IDE but I cannot see the created on the filesystem file.
I have this error when calling the web service
SEVERE: ERROR StatusLogger Unknown object "logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored
SEVERE: ERROR StatusLogger root contains an invalid element or attribute "priority"
SEVERE: ERROR StatusLogger Unknown object "root" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored
could someone pls help or give some advice I googled and stackoverflowed but without chance.
Paolo
I think that your log4j2.xml file is mixed with the old log4j style xml.
I'm having the same trouble as you when it comes to appending hibernate log to my application's log file. But I think that I can help with the logger error.
Try this file instead (and note the changes that I made):
<?xml version="1.0" encoding="UTF-8" ?>
<configuration name="SOME_PROJ_NAME" status="OFF">
<appenders>
<RollingFile name="rolling-file" fileName="c:/tmp/Program-Name.log" filePattern="c:/tmp/$${date:yyyy-MM}/Program-Name-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout>
<pattern>%d{ABSOLUTE} [%t] %-5p %c{1} - %m%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true"/>
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
</RollingFile>
</appenders>
<loggers>
<root level="info"
<appender-ref ref="rolling-file"/>
</root>
<logger name="org.hibernate level="info">
<appender-ref ref="rolling-file"/>
</logger>
</loggers>
</configuration>
It is quite similar to the one that I'm using. Note that this file should be on classpath for log4j2 auto configuration to kick in.
The most important thing you should do when using the net to configure log4j2 is that you're looking at log4j2 and not log4j style configuration.
I suggest that you look in http://logging.apache.org/log4j/2.x/ for further info. They have a good downloadable pdf that you can check out.
In addition, check out my question about a similar problem.
After following the instructions on the following pages:
http://wiki.orbeon.com/forms/doc/developer-guide/xforms-logging
http://wiki.orbeon.com/forms/doc/developer-guide/configuration-properties
I have generated my log4j.xml and properties-local.xml files according the the instructions on the pages above and inserted them into the $TOMCAT_HOME/webapps/orbeon/WEB-INF/resources/config directory.
After restarting tomcat and building a few forms with the builder, I have been unable to locate any log information. There is no orbeon.log file on my system and no orbeon information in my tomcat log files either. Additionally I have run tomcat in debug mode to use remote debugging in IntelliJ and receive no output to the console.
I'm building the webapp myself using IntelliJ with the latest on https://github.com/orbeon/orbeon-forms/tree/4.0.0.m10-ce
currently commit 51f0e8f1b396336c612c16655e39abe6b807214b
I'm using Ubuntu 12.04 and running orbeon in Tomcat6.
I'm very new to orbeon development so I'm hoping the problem is something simple.
Any help would be greatly appreciated. Thanks.
Update:
I tried setting up the logger for an absolute path with no results, here is my current configuration (except with actual absolute paths).
log4j.xml
<!-- This is the standard log appender to the console (System.out) -->
<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<param name="Encoding" value="UTF-8"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p %c{1} %x - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="debug"/>
</filter>
</appender>
<!-- Logging to a single file, typically used in development when you don't want
to be dealing with multiple files generated by the RollingFileAppender.
See: http://logging.apache.org/log4j/docs/api/org/apache/log4j/FileAppender.html -->
<appender name="SingleFileAppender" class="org.apache.log4j.FileAppender">
<param name="File" value="/Absolute_Path_To_$TOMCAT_HOME/logs/orbeon.log"/>
<param name="Append" value="false" />
<param name="Encoding" value="UTF-8"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p %c{1} %x - %m%n"/>
</layout>
</appender>
<!-- Logging to a rolling files. Every time the file exceeds a certain size, a backup
is created and the file used for logging is truncated.
See: http://logging.apache.org/log4j/docs/api/org/apache/log4j/RollingFileAppender.html -->
<appender name="RollingFileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="../logs/orbeon.log"/>
<param name="MaxFileSize" value="5MB"/>
<param name="maxBackupIndex" value="200"/>
<param name="Append" value="false" />
<param name="Encoding" value="UTF-8"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p %c{1} %x - %m%n"/>
</layout>
</appender>
<!-- XForms engine activity, see http://wiki.orbeon.com/forms/doc/developer-guide/xforms-logging -->
<category name="org.orbeon.oxf.xforms.processor.XFormsServer">
<priority value="debug"/>
</category>
<!-- To enable logging for any of the sub-systems below, copy that section outside of the comment block -->
<category name="org.orbeon.oxf.properties.Properties">
<priority value="debug"/>
</category>
<category name="org.orbeon.oxf.processor.pipeline.TeeProcessor">
<priority value="debug"/>
</category>
<category name="org.orbeon.oxf.processor.pipeline.choose.ConcreteChooseProcessor">
<priority value="debug"/>
</category>
<category name="org.orbeon.oxf.processor.generator.URLGenerator">
<priority value="debug"/>
</category>
<category name="org.orbeon.oxf.processor.xmldb.XMLDBProcessor">
<priority value="debug"/>
</category>
<category name="org.orbeon.oxf.processor.sql.SQLProcessor">
<priority value="debug"/>
</category>
<category name="org.orbeon.oxf.processor.PageFlowControllerProcessor">
<priority value="debug"/>
</category>
<category name="org.orbeon.oxf.processor.generator.RequestGenerator">
<priority value="debug"/>
</category>
<category name="org.orbeon.oxf.webapp.OPSSessionListener">
<priority value="info"/>
</category>
<category name="org.orbeon.oxf.webapp.OPSServletContextListener">
<priority value="info"/>
</category>
<!---->
<!-- Prevent extra display of eXist paging activity -->
<category name="org.exist.storage.btree.Paged">
<priority value="warn"/>
</category>
<category name="org.exist.storage.DBBroker">
<priority value="warn"/>
</category>
<category name="org.exist.storage.BrokerPool">
<priority value="warn"/>
</category>
<!-- You decide here which one of the loggers listed above you want to use. -->
<root>
<priority value="info"/>
<!--<appender-ref ref="ConsoleAppender"/>-->
<!--<appender-ref ref="ChainsawAppender"/>-->
<appender-ref ref="SingleFileAppender"/>
<!--<appender-ref ref="RollingFileAppender"/>-->
</root>
properties-local.xml
<properties xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
<property as="xs:NMTOKENS" name="oxf.xforms.logging.debug"
value="document model submission control event action analysis server server-body html submission-details submission-body"/>
</properties>
Update2
Following some of the suggestions, I've ensured that write permissions is not the issue. I've also tried using the ConsoleAppender and still got no output, but the webapp also crashed after a few minutes and I found this exception in the tomcat log files.
WARNING: Cannot serialize session attribute orbeon.resources.dynamic.cb088a8a347ad72a00012a9d8569b5e9c5dd6381 for session 29AE194AA69E0D51C111F5035C219E7B
java.io.NotSerializableException: scala.collection.JavaConversions$MapWrapper
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:1585)
at org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:1015)
at org.apache.catalina.session.StandardManager.doUnload(StandardManager.java:528)
at org.apache.catalina.session.StandardManager.unload(StandardManager.java:469)
at org.apache.catalina.session.StandardManager.stop(StandardManager.java:678)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4882)
at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:936)
at org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:1359)
at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:1330)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:326)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1098)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1110)
at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:468)
at org.apache.catalina.core.StandardService.stop(StandardService.java:604)
at org.apache.catalina.core.StandardServer.stop(StandardServer.java:788)
at org.apache.catalina.startup.Catalina.stop(Catalina.java:662)
at org.apache.catalina.startup.Catalina$CatalinaShutdownHook.run(Catalina.java:706)
The logs folder should be available inside Tomcat folder if you declare log4j as below
<appender name="SingleFileAppender" class="org.apache.log4j.FileAppender">
<param name="File" value="../logs/orbeon.log"/>
<param name="Append" value="false" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p %c{1} %x - %m%n"/>
</layout>
</appender>
and
<!-- You decide here which one of the loggers listed above you want to use. -->
<root>
<priority value="debug"/>
<!--<appender-ref ref="ConsoleAppender"/>-->
<!--<appender-ref ref="ChainsawAppender"/>-->
<appender-ref ref="SingleFileAppender"/>
<!--<appender-ref ref="RollingFileAppender"/>-->
</root>
If you have simply placed the Orbeon war file in webapps folder, then i suggest to remove the .war file once the server is started. After server start, tomcat unpacks the war and creates a folder. If .war is not removed everytime you restart the tomcat server, it will unpack and overwrites in the same folder again.
With the default log4j.xml, the SingleFileAppender is being used, and the file it writes to is referenced using a relative path:
<param name="File" value="../logs/orbeon.log"/>
So the location of the file on disk will depend on the directory from which you start Tomcat. It is not uncommon to start Tomcat from its bin directory, in which case the log file will end up in Tomcat's logs directory. But if you're starting Tomcat from a different location, or would like the log file to end up in the different directory, you can edit your log4j.xml and put there an absolute path to the orbeon.log.