I am trying to deploy a grails application on JBoss EAP, the problem is that no output from my application is logged except for stdout and stderr.
I really don't understand how the logging works in this case since jboss uses some internal logging system and grails uses log4j.
This is my logging configuration in standalone.xml:
<subsystem xmlns="urn:jboss:domain:logging:1.1">
<console-handler name="CONSOLE">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
</console-handler>
<periodic-rotating-file-handler name="FILE">
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-rotating-file-handler>
<logger category="com.arjuna">
<level name="WARN"/>
</logger>
<logger category="org.apache.tomcat.util.modeler">
<level name="WARN"/>
</logger>
<logger category="sun.rmi">
<level name="WARN"/>
</logger>
<logger category="jacorb">
<level name="WARN"/>
</logger>
<logger category="jacorb.config">
<level name="ERROR"/>
</logger>
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
</subsystem>
Which is default.
This log4j configuration is in my Config.groovy:
// log4j configuration
log4j = {
// Example of changing the log pattern for the default console appender:
//
//appenders {
// console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
//}
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
all additivity: false, console: [
'grails.app.controllers.com.redhat.theses',
'grails.app.domain.your.com.redhat.theses',
'grails.app.services.com.redhat.theses',
'grails.app.taglib.com.redhat.theses',
'grails.app.conf.com.redhat.theses',
'grails.app.filters.com.redhat.theses'
]
}
I really don't understand this logging stuff, it is so confusing, all I want is to log at least all errors, for starters. One would think that such a crucial feature works by default.
If I set this property when starting JBoss:
./standalone.sh -Dorg.jboss.as.logging.per-deployment=false
it works exactly as I want. But is it all right? Why do I have to set this property in order to get such a crucial function as logging, really?
Thank you so much for any help, I am sorry if I sound a bit arrogant, I have been trying to figure this out for hours and I am still where I was at the beginning.
The org.jboss.as.logging.per-deployment environment variable, AKA host property, AKA environment property tells JBoss which logging config to use. Setting it to true tells JBoss to use the logging config in the application being deployed. I would not know how to set that up in Grails Config.groovy. I do the config in JBoss after setting that host property to false. False means use the logging config in JBoss.
In JBoss set the property to false and then just create a grails.app category and have it log to a file Handler. That works for me in Grails and EAP 6.0 running in domain mode.
Related
After configuring Apache James 3.7.2 with spring wiring, I noticed that the log4j2 xml configuration file defines the MAILETCONTAINER appender 4 times.
https://github.com/apache/james-project/blob/3.7.x/server/apps/spring-app/src/main/resources/log4j2.xml
<RollingFile name="MAILETCONTAINER" fileName="${logDir}/james_mailetcontainer.log"
<RollingFile name="MAILETCONTAINER" fileName="${logDir}/james_mailetcontainer.log"
<RollingFile name="MAILETCONTAINER" fileName="${logDir}/james_mailetcontainer.log"
<RollingFile name="MAILETCONTAINER" fileName="${logDir}/james_mailetcontainer.log"
<Logger name="org.apache.james.mailetcontainer" additivity="false">
<Logger name="org.apache.james.mailetcontainer" additivity="false">
<Logger name="org.apache.james.mailetcontainer" additivity="false">
<Logger name="org.apache.james.mailetcontainer" additivity="false">
Is this simply a misconfiguration?
I have deleted the duplicate entries on my local server and the logging behaviour appears to not have been adversely affected.
I have a java application. I have created a log4j2.xml under src folder and that works as expected.
This java application depends on another java package. I tried creating a similar log4j2.xml in this package to format all the logging done in package, But this does not seem to work. And all the logs in the package seems to be going to console in default formatting.
Thoughts?
In this case you need to have different Appenders
SO the config will be as below
<!-- Package 1 appender declaration -->
<appender name="one" class="org.apache.log4j.FileAppender">
...
</appender>
<!-- Package 2 appender declaration -->
<appender name="two" class="org.apache.log4j.FileAppender">
...
</appender>
<!-- logger package com.myapp.app.one -->
<logger name="com.myapp.app.one">
<level value="DEBUG" />
<appender-ref ref="one"/>
</logger>
<!-- logger for package com.myapp.app.two -->
<logger name="com.myapp.app.two">
<level value="DEBUG" />
<appender-ref ref="two"/>
</logger>
I have an unpacked EAR deployed at $JBOSS_HOME/standalone/deployments in Wildfly-8.2.0.Final AS. It contains unpacked WAR and application jar files.
HelloWorldEar-0.0.1-SNAPSHOT.ear
-HelloWorldServlet-0.0.1-SNAPSHOT.war
-lib
-META-INF
-aspectjrt-1.8.6.jar
-HelloWorldAnnotation-0.0.1-SNAPSHOT.jar
-HelloWorldAspect-0.0.1-SNAPSHOT.jar
-HelloWorldCommonLib-0.0.1-SNAPSHOT.jar
-HelloWorldEJB-0.0.1-SNAPSHOT.jar
-log4j2.xml
lib folder of EAR contains log4j2 related APIs for providing logging feature.
lib
-commons-logging-1.2.jar
-HelloWorldLog4jPlugin-0.0.1-SNAPSHOT.jar (Jar containing custom log4j2 plugins)
-log4j-api-2.4.1.jar
-log4j-core-2.4.1.jar
-log4j-jcl-2.4.1.jar
-log4j-web-2.4.1.jar
I am initializing log4j2 configuration by initializing log4j2.xml using in a startup singleton bean in HelloWorldEJB-0.0.1-SNAPSHOT.jar.
String path = System.getProperty("jboss.home.dir")
+ "/standalone/deployments/HelloWorldEar-0.0.1-SNAPSHOT.ear/log4j2.xml";
ConfigurationSource source;
File configFile = new File(path);
try {
source = new ConfigurationSource(new FileInputStream(configFile), configFile);
Configurator.initialize(null, source);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
log4j2.xml content
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace">
<Appenders>
<RollingFile name="SERVER_FILE" fileName="${sys:LOGS}/sample.log" filePattern="${sys:LOGS}/sample.log.%i" append="true">
<PatternLayout>
<pattern>%d %-5p [%c{1}] [EventId: %e] [%t] %m%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="500 KB" />
</Policies>
<DefaultRolloverStrategy max="5"/>
</RollingFile>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout>
<pattern>%d{ABSOLUTE} %-5p [%c{1}] %m%n</pattern>
</PatternLayout>
</Console>
</Appenders>
<Loggers>
<Logger name="com.test.prototype.log4j" level="debug">
<AppenderRef ref="SERVER_FILE"/>
</Logger>
<Root level="debug" additivity="false">
<AppenderRef ref="CONSOLE"/>
</Root>
</Loggers>
</Configuration>
All the sub-packages and classes are defined under the package com.test.prototype.log4j.
Log statements added in the classes of HelloWorldEJB-0.0.1-SNAPSHOT.jar gets logged in the log file.
My issue is that 1. log statements from other application jars and WAR are not getting logged into the log file.
2. Logging not working through commons-logging API though required system parameters for log4j2 is added.
System.setProperty("org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.Log4JLogger");
I have tried adding the class-path in the application jars and below listener in the web.xml of WAR file but nothing worked.
org.apache.logging.log4j.web.Log4jServletContextListener
I need to have log4j2.xml under EAR and it should server for the all the application jars and WARs added in the EAR. Could anyone please help me about how to resolve this issue.
Have you tried specifying the log4j2.xml config file location with system property -Dlog4j.configurationFile=path/to/log4j2.xml?
I suspect that the way you're initializing log4j now is not visible from other WARs.
If this fails, please raise this issue on the log4j2 Jira issue tracker. https://issues.apache.org/jira/browse/LOG4J2
I'm trying to stream a basic hello world log message to show up in chainsaw from log4j2. I don't care if it uses "Zeroconf" or not, I just want something that works. I know that my test program is logging messages since they show on the console, and I know it's finding my config file because I can change the format of the messages that get printed in the console, but that's all I know.
My config file (containing various failed guesses):
<?xml version="1.0" encoding="UTF-8"?>
<configuration advertiser="org.apache.logging.log4j.core.net.MulticastDNSAdvertiser">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %m%n"/>
</Console>
<File name="testFile" fileName="logs/test.log" bufferedIO="false" advertiseURI="file://localhost/home/matt/code/ade/logs/test.log" advertise="true">
<XMLLayout />
</File>
<SocketAppender name="socketTest" host="localhost" immediateFlush="true" port="4560" protocol="TCP" advertiseURI="http://localhost" advertise="true">
<XMLLayout />
</SocketAppender>
</appenders>
<loggers>
<root level="TRACE">
<appender-ref ref="Console"/>
<appender-ref ref="testFile"/>
<appender-ref ref="socketTest"/>
</root>
</loggers>
</configuration>
I've tried various combinations of: including jmdns.jar on the classpath, restarting chainsaw at various points, and getting frustrated, but nothing has helped.
Any ideas?
Edit: I figured out why it couldn't read the log files I was saving to disk, (I hadn't been using XMLLayout) so I've updated the question to reflect that I now only need to get streaming working.
The 'advertiser' uses the log4j2 plugin mechanism, so you must provide the 'name' defined on the Advertiser in the configuration - not the fully-qualified class name.
The log4j2 advertisement mechanism currently supports advertisement of FileAppenders and SocketAppenders. However, Chainsaw only supports discovery of log4j2 FileAppenders which are advertised with a PatternLayout. XMLLayout support will show up in the near future.
The latest developer snapshot of Chainsaw must be used in order to leverage log4j2's advertiser mechanism. Chainsaw tarball and DMG available at: http://people.apache.org/~sdeboy/
Chainsaw will discover the advertised fileappender configuration and parse (and tail if you get the latest Chainsaw developer build) the log file - no Chainsaw configuration required.
Note, you need to use a PatternLayout, and JMDNS must be on the classpath of the application using this appender configuration.
Here is an example Log4j2 -appender- configuration that will advertise a fileappender configuration:
<?xml version="1.0" encoding="UTF-8"?>
<configuration advertiser="multicastdns">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %m%n"/>
</Console>
<File name="testFile" fileName="logs/test.log" bufferedIO="false" advertiseURI="file:///localhost/home/matt/code/ade/logs/test.log" advertise="true">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %m%n"/>
</File>
</appenders>
<loggers>
<root level="TRACE">
<appender-ref ref="Console"/>
<appender-ref ref="testFile"/>
</root>
</loggers>
</configuration>
Once you have started your app that is using the appender
configuration, open the 'Zeroconf' tab in Chainsaw.
You should see a row with your appender's name (assuming you added
jmdns to the classpath for the app using the fileappender
configuration).
You can click 'Autoconnect' if you'd like to always start Chainsaw
with this configuration if it is available.
Next, double-click
on the row with the appender name and Chainsaw will start parsing and tailing your log file.
The advertised URL provided in your file appender
configuration must be accessible network-wise to Chainsaw (looks like you are working
locally with Chainsaw and your fileappender, so file:/// paths will
work fine - note the three slashes).
Chainsaw will work best if there are delimiters around each field - square brackets, dashes, etc. as long as that character won't be present in the field you are delimiting.
I am playing around with a Struts2 webapp (Struts 2.2.3.1) running on Tomcat 6.
As seen in several tutorials, I have the following bit in my log4j.xml, which is deployed in the webapp's WEB-INF/classes directory:
<logger name="com.opensymphony">
<level value="DEBUG" />
</logger>
<logger name="org.apache.struts2">
<level value="DEBUG" />
</logger>
After setting the property log4j.debug=true in my Tomcat confiuration, I find (as expected) the following output in the Tomcat log:
log4j: DocumentBuilderFactory is: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
log4j: debug attribute= "null".
log4j: Ignoring debug attribute.
log4j: Threshold ="null".
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [com.opensymphony] additivity to [true].
log4j: Level value for com.opensymphony is [DEBUG].
log4j: com.opensymphony level set to DEBUG
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [org.apache.struts2] additivity to [true].
log4j: Level value for org.apache.struts2 is [DEBUG].
log4j: org.apache.struts2 level set to DEBUG
log4j: Level value for root is [DEBUG].
log4j: root level set to DEBUG
However, no Struts debugging messages can be found at all in any logfile.
My log4j version is 1.2.14.
How can I properly control Struts' logging?
If i am correct you have to define some sort of Appender in order to redirect the log output to the log file.
in default case struts2 log will be getting displayed on the console.Define something like this in your log4j file
<appender name="FA" class="org.apache.log4j.FileAppender">
<param name="File" value="sample.log"/>
<param name="Threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-4r [%t] %-5p %c %x - %m%n" />
</layout>
</appender>
You have to tell log4j where to redirect the logout