Grails log4J Logging question on linux - linux

I have been very frustrated about this.
I am trying to do the following:
Log all application related logs in application.log that are INFO or above
Understand what controls the configuration for catalina.out
Log only WARN to catalina.out
I am running my server on ubuntu and I have the default configuration for tomcat which includes a conf directory with a logging.properties. I renamed this file to l.p so it wouldn't conflict. (Not sure if this is a good idea)
In my config file, I have:
def catalinaBase = System.properties.getProperty('catalina.base')
if (!catalinaBase) catalinaBase = '.' // just in case
def logDirectory = "${catalinaBase}${File.separator}logs"
println "Log Directory: ${logDirectory}"
log4j = {
appenders {
rollingFile name: 'applog', file: "${logDirectory}${File.separator}application.log", layout: pattern(conversionPattern: '%d{dd-MM-yyyy HH:mm:ss,SSS} %5p %c{1} - %m%n'), maxFileSize: 1024
}
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'
warn 'org.mortbay.log'
info applog: 'grails.app'
root {
info 'applog'
}
}
As a result, I am getting three logs:
catalina.2011-01-17.log catalina.out localhost.2011-01-17.log
The catalina.out has the following output:
Log Directory: /var/lib/tomcat6/logs
log4j:WARN No appenders could be found for logger (org.apache.commons.beanutils.PropertyUtils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
log4j:ERROR WARNING: Exception occured configuring log4j logging: Cannot invoke org.apache.log4j.FileAppender.setFile - argument type mismatch
I do NOT see the application.log in the log file directory. Any help would be appreciated I am really frustrated about this.
One more thing, in windows everything come out to the console and the application.log is created in the .grails\1.3.5\projects\<appnmae>\tomcat directory

Your problem is obviously that there's a type mismatch. Specifically, log4j is expecting a String when you're giving it a GString. Try replacing:
"${logDirectory}${File.separator}application.log"
With this:
"${logDirectory}${File.separator}application.log".toString()
EDIT: Please read this BUG

Related

logstash not working with log4j via SocketAppender

I have been trying (and failing) to get logstash working with log4j SocketAppender.
Here is my log4j.properties:
log4j.appender.tcp=org.apache.log4j.net.SocketAppender
log4j.appender.tcp.Port=4560
log4j.appender.tcp.RemoteHost=localhost
log4j.appender.tcp.ReconnectionDelay=10000
log4j.appender.tcp.Application=playground
logstash.conf
input {
log4j {
}
}
output {
stdout {}
}
I have set logstash logging level to TRACE and sent a log message to it. Afterward I found the following lines in the console log of logstash:
11:44:35.778 [Ruby-0-Thread-21: c:/_work/issues/log4j_socketappender/logstash-5.0.1/vendor/bundle/jruby/1.9/gems/logstash-input-log4j-3.0.3-java/lib/logstash/inputs/log4j.rb:155] DEBUG logstash.inputs.log4j - Accepted connection {:client=>"127.0.0.1:61823", :server=>"0.0.0.0:4560"}
11:44:35.795 [Ruby-0-Thread-21: c:/_work/issues/log4j_socketappender/logstash-5.0.1/vendor/bundle/jruby/1.9/gems/logstash-input-log4j-3.0.3-java/lib/logstash/inputs/log4j.rb:155] DEBUG logstash.inputs.log4j - Closing connection {:client=>"127.0.0.1:61823", :exception=>#<IOError: org.apache.log4j.spi.LoggingEvent; class invalid for deserialization>}
Any help is much appreciated.
It's a bug. There is a workaround:
Locate file logstash-core/lib/jars.rb in the Logstash installation directory, comment out the below line:
require_jar('org.apache.logging.log4j', 'log4j-1.2-api', '2.6.2')
Discussed in here: GitHub Issue

Eclipse4 RCP: Configure log4j with fragment plugin

So this is a follow up issue that arrised with this question: Using log4j in eclipse RCP doesn't work.
So far I'm able to use the log4j API inside my RCP but when running it with the following command
Category CAT = Category.getInstance(getClass().getSimpleName());
CAT.debug("Application has been started");
I get that exception:
No appenders could be found for category (MyPlugin).
Please initialize the log4j system properly.
I have created a fragment plugin containing a file called log4j.properties and the fragment host is the plugin containing the log4j API. The property file lives in the "root" of the fragment plugin
My log4j.properties file looks like that:
# Set root logger level to debug and its only appender to default.
log4j.rootLogger=debug, default
# default is set to be a ConsoleAppender.
log4j.appender.default=org.apache.log4j.ConsoleAppender
# default uses PatternLayout.
log4j.appender.default.layout=org.apache.log4j.PatternLayout
log4j.appender.default.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
Any ideas what I'm doing wrong?
I am not sure, what is the purpose of using fragment for holding configuration. Try to place your log4j,properties (note that the name of the file is misspelled in your answer) directly to your plugin root folder. In the Activator.start() execute following code:
public void start(BundleContext context) throws Exception {
super.start(context);
URL installURL = plugin.getBundle().getEntry("/");
String installPath = Platform.asLocalURL(installURL).getFile();
PropertyConfigurator.configure(installPath +"/log4j.properties");
}
First of all, category documentation says: This class has been deprecated and replaced by the Logger subclass.
Secondly, Category has to be mapped to an appender:
log4j.category.MyPlugin=info,MyPlugin
log4j.appender.MyPlugin=org.apache.log4j.DailyRollingFileAppender
log4j.appender.MyPlugin.layout=org.apache.log4j.PatternLayout
log4j.appender.MyPlugin.layout.ConversionPattern={%t} %d - [%p] %c: %m %n
log4j.appender.MyPlugin.file=C:/logs/MyPlugin.log
log4j.appender.MyPlugin.DatePattern='.' yyyy-MM-dd-HH-mm

WARN No appenders could be found for logger (org.apache.accumulo.start.classloader.AccumuloClassLoader)

Does anyone know how to get rid of the following warnings when starting accumulo:
log4j:WARN No appenders could be found for logger (org.apache.accumulo.start.classloader.AccumuloClassLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
I am running accumulo 1.4.0 hadoop 0.20.2 and zookeeper 3.3.3. I understand this warning happens because the class can not find the log4j.properties file and yes I have read http://logging.apache.org/log4j/1.2/manual.html. My log4j.properties file has the following lines copied from an accumulo 1.4.3 log4j file (I dont have the option to upgrade my system to 1.4.3):
# default logging properties:
# by default, log everything at INFO or higher to the console
log4j.rootLogger=INFO,A1
# hide Jetty junk
log4j.logger.org.mortbay.log=WARN,A1
# hide "Got brand-new compresssor" messages
log4j.logger.org.apache.hadoop.io.compress=WARN,A1
# hide junk from TestRandomDeletes
log4j.logger.org.apache.accumulo.server.test.TestRandomDeletes=WARN,A1
# hide almost everything from zookeeper
log4j.logger.org.apache.zookeeper=ERROR,A1
# hide AUDIT messages in the shell, alternatively you could send them to a different logger
log4j.logger.org.apache.accumulo.core.util.shell.Shell.audit=WARN,A1
# Send most things to the console
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} [%-8c{2}] %-5p: %m%n
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
I have put this log4j file everyone. In the accumulo/bin folder, in the accumulo/conf folder, in the accumulo/lib folder but can not get rid of this warning (I know it has to go on the accumulo class path but dont know where that is). I also can't pass a log4j.configuration option to the java compiler because the accmulo executable comes pre-compiled (I just run it).
Thanks in advance for the help.
EDIT: Below is the result of an "accumulo classpath" command on my system:
[admin-cloud#NODE1 bin]$ echo $ACCUMULO_HOME
/accumulo/accumulo-1.4.0
[admin-cloud#NODE1 bin]$ accumulo classpath
Accumulo List of classpath items are:
file:/accumulo/accumulo-1.4.0/lib/commons-collections-3.2.jar
file:/accumulo/accumulo-1.4.0/lib/commons-configuration-1.5.jar
file:/accumulo/accumulo-1.4.0/lib/log4j-1.2.16.jar
file:/accumulo/accumulo-1.4.0/lib/libthrift-0.6.1.jar
file:/accumulo/accumulo-1.4.0/lib/commons-jci-core-1.0.jar
file:/accumulo/accumulo-1.4.0/lib/commons-lang-2.4.jar
file:/accumulo/accumulo-1.4.0/lib/commons-logging-api-1.0.4.jar
file:/accumulo/accumulo-1.4.0/lib/accumulo-server-1.4.0.jar
file:/accumulo/accumulo-1.4.0/lib/accumulo-start-1.4.0.jar
file:/accumulo/accumulo-1.4.0/lib/commons-jci-fam-1.0.jar
file:/accumulo/accumulo-1.4.0/lib/jline-0.9.94.jar
file:/accumulo/accumulo-1.4.0/lib/examples-simple-1.4.0.jar
file:/accumulo/accumulo-1.4.0/lib/cloudtrace-1.4.0.jar
file:/accumulo/accumulo-1.4.0/lib/commons-logging-1.0.4.jar
file:/accumulo/accumulo-1.4.0/lib/accumulo-core-1.4.0.jar
file:/accumulo/accumulo-1.4.0/lib/commons-io-1.4.jar
file:/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.jar
file:/hadoop/hadoop-0.20.2/conf/
file:/hadoop/hadoop-0.20.2/hadoop-0.20.2-examples.jar
file:/hadoop/hadoop-0.20.2/hadoop-0.20.2-test.jar
file:/hadoop/hadoop-0.20.2/hadoop-0.20.2-tools.jar
file:/hadoop/hadoop-0.20.2/hadoop-0.20.2-ant.jar
file:/hadoop/hadoop-0.20.2/hadoop-0.20.2-core.jar
file:/hadoop/hadoop-0.20.2/lib/log4j-1.2.15.jar
file:/hadoop/hadoop-0.20.2/lib/jasper-runtime-5.5.12.jar
file:/hadoop/hadoop-0.20.2/lib/slf4j-log4j12-1.4.3.jar
file:/hadoop/hadoop-0.20.2/lib/commons-httpclient-3.0.1.jar
file:/hadoop/hadoop-0.20.2/lib/mockito-all-1.8.0.jar
file:/hadoop/hadoop-0.20.2/lib/jetty-6.1.14.jar
file:/hadoop/hadoop-0.20.2/lib/oro-2.0.8.jar
file:/hadoop/hadoop-0.20.2/lib/servlet-api-2.5-6.1.14.jar
file:/hadoop/hadoop-0.20.2/lib/junit-3.8.1.jar
file:/hadoop/hadoop-0.20.2/lib/commons-logging-api-1.0.4.jar
file:/hadoop/hadoop-0.20.2/lib/commons-codec-1.3.jar
file:/hadoop/hadoop-0.20.2/lib/core-3.1.1.jar
file:/hadoop/hadoop-0.20.2/lib/jets3t-0.6.1.jar
file:/hadoop/hadoop-0.20.2/lib/hsqldb-1.8.0.10.jar
file:/hadoop/hadoop-0.20.2/lib/slf4j-api-1.4.3.jar
file:/hadoop/hadoop-0.20.2/lib/jasper-compiler-5.5.12.jar
file:/hadoop/hadoop-0.20.2/lib/jetty-util-6.1.14.jar
file:/hadoop/hadoop-0.20.2/lib/commons-net-1.4.1.jar
file:/hadoop/hadoop-0.20.2/lib/commons-logging-1.0.4.jar
file:/hadoop/hadoop-0.20.2/lib/commons-cli-1.2.jar
file:/hadoop/hadoop-0.20.2/lib/xmlenc-0.52.jar
file:/hadoop/hadoop-0.20.2/lib/kfs-0.2.2.jar
file:/hadoop/hadoop-0.20.2/lib/commons-el-1.0.jar
Line 84 of bin/accumulo in Apache Accumulo 1.4.0 sets the variable XML_FILES to $ACCUMULO_HOME/conf and then adds XML_FILES to the CLASSPATH variable which is later passed to the java command.
https://svn.apache.org/repos/asf/accumulo/tags/1.4.0/bin/accumulo
It sounds you have a misconfiguration of ACCUMULO_HOME either through your shell environment or in $ACCUMULO_HOME/conf/accumulo-env.sh.
I was troubleshooting an installation someone else set up that was having the same problem. My solution to this problem was simply that there actually was no log4j.properties in the conf directory! So I just copied up one of the log4j.properties from the conf/examples directory, restarted and everything worked like it should!

Log4j logs hidden or swallowed when deployed to CloudFoundry

I've just deployed my first app to CloudFoundry, and I use log4j. When I deploy the app to a local tomcat server, the logs print just fine as all is well. But, when I use the "vmc logs " command to get the logs from the instance on CloudFoundry, I only get the tomcat initialization logs and this message:
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Anything further that I've printed with log4j is not visible. System.out.println messages show up, but no log4j messages.
I've placed my log4j.properties file in my WEB-INF directory, and here are its contents:
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=INFO, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5p %-35c{1} %m%n
log4j.logger.org.springframework=WARN
My logger object is created as would probably be expected in my classes:
private static Logger log = Logger.getLogger(MyClass.class);
Any suggestions as to what configuration I'm missing to have my log4j logs show up in my CloudFoundry logs? Or am I retrieving them incorrectly?
Is Log4j set to output to STDOUT by default? 'vmc logs' will only return the contents of STDOUT, STDERR and the staging log files.
If you app is logging to a different file then use 'vmc file' to view the content.

Procrun and log4 configuration

I'm using procrun to start a Windows Service for my java process. I can get the service to start, but the log4j configuration that I set up doesn't seem to be working. This is what I see in the stderr file that procrun creates:
log4j:WARN No appenders could be found for logger (com.jar.aa.MainEntry).
log4j:WARN Please initialize the log4j system properly.
Here is the command that I specify to install the service:
%INSTALL_SERVICE_CMD% //IS//SERVICEAGENT --DisplayName="DispName" --Install=%SERVICE_EXE_HOME%\prunsrv.exe --LogPath=%INSTALLER_HOME% --LogLevel=Info --StdOutput=auto --StdError=auto --StartMode=Java --StopMode=Java --Jvm=auto --Startup=auto --JvmMx=512 ++JvmOptions=-XX:MaxPermSize=128m --StartPath=%START_CLASS_PATH%\ --Classpath=%CLASSPATH%;MyJar.jar --StartClass=com.jar.aa.MainEntry --StopClass=com.jar.aa.ExitEntry ++StopParams=--stop ++JvmOptions=-Dfile.encoding=UTF8 ++JvmOptions=-Dlog4j.configuration=log4j.properties ++JvmOptions=-Dorg.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
I have my log4j properties placed in the same directory as this install script.
Can anyone tell me what I might be missing? Any help would be greatly appreciated.
Thanks,
K
I'm not sure if my memories are correct, but i think i had the same problem and solved it by including the log4j configuration file in my jar file. In your case MyJar.jar.
If it still gives troubles try placing your jar at the beginning of your classpath definition. HTH

Resources