log4j syslogappender stack trace output not on the same line - java

I am trying to get centralised logging working with log4j and rsyslog.
What I have so far
Solr running inside tomcat6 on RHEL6, using the following log4j and sl4j libs
# lsof -u tomcat | grep log4j
java 14503 tomcat mem REG 253,0 9711 10208 /usr/share/java/tomcat6/slf4j-log4j12-1.6.6.jar
java 14503 tomcat mem REG 253,0 481535 10209 /usr/share/java/tomcat6/log4j-1.2.16.jar
java 14503 tomcat mem REG 253,0 378088 1065276 /usr/share/java/log4j-1.2.14.jar
java 14503 tomcat 20r REG 253,0 378088 1065276 /usr/share/java/log4j-1.2.14.jar
java 14503 tomcat 21r REG 253,0 481535 10209 /usr/share/java/tomcat6/log4j-1.2.16.jar
java 14503 tomcat 35r REG 253,0 9711 10208 /usr/share/java/tomcat6/slf4j-log4j12-1.6.6.jar
#
Solr is using the following log4j.properties file (via -Dlog4j.configuration=file:///opt/solr/lib/log4j.properties)
# Logging level
log4j.rootLogger=INFO, file, CONSOLE, SYSLOG
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x \u2013 %m%n
#- size rotation with log cleanup.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.MaxFileSize=4MB
log4j.appender.file.MaxBackupIndex=9
#- File to log to and log format
log4j.appender.file.File=/var/log/tomcat6/solr.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%-5p - %d{yyyy-MM-dd HH:mm:ss.SSS}; %C; %m\n
log4j.logger.org.apache.zookeeper=WARN
log4j.logger.org.apache.hadoop=WARN
# set to INFO to enable infostream log messages
log4j.logger.org.apache.solr.update.LoggingInfoStream=OFF
#- Local syslog server
log4j.appender.SYSLOG=org.apache.log4j.net.SyslogAppender
log4j.appender.SYSLOG.syslogHost=localhost
log4j.appender.SYSLOG.facility=LOCAL1
log4j.appender.SYSLOG.layout=org.apache.log4j.PatternLayout
log4j.appender.SYSLOG.layout.ConversionPattern=${sysloghostname} %-4r [%t] java %-5p %c %x %m%n
log4j.appender.SYSLOG.Header=true
On the same server I have rsyslog running and accepting log messages from log4j.
# rpmquery -a | grep syslog
rsyslog-5.8.10-7.el6_4.x86_64
#
rsyslog config
# #### MODULES ####
$MaxMessageSize 32k
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imklog # provides kernel logging support (previously done by rklogd)
$ModLoad imfile # provides file monitoring support
#
$ModLoad imudp.so
$UDPServerRun 514
$WorkDirectory /var/lib/rsyslog # where to place spool files
# #### GLOBAL DIRECTIVES ####
# # Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$IncludeConfig /etc/rsyslog.d/*.conf
$ActionQueueType LinkedList # run asynchronously
$ActionQueueFileName fwdRule1 # unique name prefix for spool files
$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
$ActionResumeRetryCount -1 # infinite retries if host is down
$ActionSendStreamDriverMode 0 # require TLS for the connection
$ActionSendStreamDriverAuthMode anon # chain and server are verified
#local1.*;*.* ##(o)XXXXXXXX:5544
local1.* /var/log/remote.log
# # The authpriv file has restricted access.
authpriv.* /var/log/secure
# # Log all the mail messages in one place.
mail.* -/var/log/maillog
# # Log cron stuff
cron.* /var/log/cron
# # Everybody gets emergency messages
*.emerg *
# # Save news errors of level crit and higher in a special file.
uucp,news.crit /var/log/spooler
# # Save boot messages also to boot.log
local7.* /var/log/boot.log
I am catching local1 messages from Solr's logj4 and redirecting them to /var/log/remote.log
Everything works as expected. Sample INFO message
Oct 31 13:57:08 hostname.here 3431839 [http-8080-10] java INFO org.apache.solr.core.SolrCore [collection1] webapp=/solr path=/select params={indent=true&q=*:*&wt=json&rows=1} hits=42917 status=0 QTime=1
And stack traces are on the same line as the ERROR message
Oct 31 12:27:17 hostname.here 157666248 [http-8080-7] java ERROR org.apache.solr.core.SolrCore org.apache.solr.common.SolrException: undefined field *#012#011at org.apache.solr.schema.IndexSchema.getDynamicFieldType(IndexSchema.java:1223)#012... Cut for brevity....#011at java.lang.Thread.run(Thread.java:724)#012
Note #012 as line ending and #011 tab.
Using this setup I can ship the logs to remote rsyslog server over TCP and pipe them into fluentd/elaticsearch/kibana etc... everything works as expected.
The problem
I am now trying to get another webapp running inside the same tomcat container to log as above, everything works as expected apart from stack traces, each line of a stack trace ends up on a separate line (separate syslog message)
Oct 31 12:54:47 hostname.here 4909 [main] java ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate could not get database metadata
Oct 31 12:54:47 hostname.here org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure
Oct 31 12:54:47 hostname.here
Oct 31 12:54:47 hostname.here The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
The webapp ships with it's own log4j libs and log4j.xml config. Libs are of the same version as those used by solr.
log4j.xml file for this app
<appender name="SYSLOG" class="org.apache.log4j.net.SyslogAppender">
<param name="SyslogHost" value="localhost" />
<param name="Facility" value="LOCAL1" />
<param name="Header" value="false" />
<property name="facilityPrinting" value="false"/>
<param name="Threshold" value="DEBUG" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%-4r [%t] java %-5p %c %x %m%n"/>
</layout>
</appender>
I would like to see stack traces from the new application to appear on the same line just like with Solr.
Does anyone know if this is a log4j config issue?
Many thanks.

I've been working on something similar lately (in fact, I have this question open presently you may be able to help with).
This is probably not a very good answer, but it's more information than I can fit in a comment so here you go (I hope some of it is new to you). The rsyslog imfile rsyslog documentation has this section:
ReadMode [mode]
This mode should defined when having multiline messages. The value can range from 0-2 and determines the multiline detection method.
0 (default) - line based (Each line is a new message)
1 - paragraph (There is a blank line between log messages)
2 - indented (New log messages start at the beginning of a line. If a line starts with a space it is part of the log message before it)
The imudp rsyslog docs have no such configuration option. My guess is that the UDP input module doesn't support multiline logging. Thus, each line of the stack trace is sent out as a separate log entry.
Do you have any configuration files in /etc/rsyslog.d? There may be more information in there.

Related

log4j to write log to console and also to file

I use Selenium WebDriver and log4j in my Java project. I set log4j.properties as follows:
# Define the root logger with appender file
log4j.rootLogger = DEBUG, stdout, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
# Set the name of the file
log4j.appender.FILE.File=C:/_privat/myproj/log/log.out
# Set the immediate flush to true (default)
log4j.appender.FILE.ImmediateFlush=true
# Set the threshold to debug mode
log4j.appender.FILE.Threshold=debug
# Set the append to false, overwrite
log4j.appender.FILE.Append=false
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%-20c{1}:%3L] %m%n
log4j.appender.stdout.Threshold=INFO
During execution I see only these lines instead of full log.
Starting ChromeDriver 75.0.3770.8 (681f24ea911fe754973dda2fdc6d2a2e159dd300-refs/branch-heads/3770#{#40}) on port 3320
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
jún. 14, 2019 8:26:53 DE org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
When execution is stopped I get all the log messages also to console, which was written to file. I need to see log also in console during execution.

Tomcat 8 Apache Log4j 1.2.17 Time

I recently followed this tomcat article to change my stdout log appearance while using log4j. I wanted a time stamp for each action a user takes. After following the article, I am still not receiving the desired result.
The tomcat 8 stdout log looked like:
(action.BaseAction 39 ) Calling Action
/editBlaBlaBla by: System Administrator
However I wanted to add a timestamp to each action a user takes. IE:
(action.BaseAction 2015/07/26 15:46:12 39 ) Calling Action
/editBlaBlaBla by: System Administrator
After adding the necessary jars (tomcat-juli, tomcat-juli-adapter, and log4j) to Tomcat 8.0\lib directory and adding a log4j properties file beside my logging.properties in Tomcat 8.0\conf directory.
My stdout logs look like:
2016-02-26 10:38:18 Commons Daemon procrun stdout initialized running
ControllerServlet init
Running ControllerServlet tempInit
There are no entries corresponding to user actions. My log4j.properties file:
log4j.rootLogger=stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= %d [%-6p] %c{1} - %m%n
This is how the logger is initialized in my java action classes
import org.apache.log4j.Logger;
private static final Logger logger = Logger.getLogger(MYCLASSHERE.class);
How do I go about getting the time stamp without redoing the entirety of my java logging statements?
Try this.
log4j.appender.stdout.layout.ConversionPattern=%-d{MMM dd yyyy HH:mm:ss} %-5p %C{1} %M %m%n
And your output will be like
Feb 22 2016 15:52:22 INFO ClassName MethodName StringInLogDotInfo

Unable to make jetty use logback for logging

I followed this page to install jetty on a Amazon EC2 instance of mine (Ubuntu 14.04.2 LTS). Jetty is running. However, I can't make it use logback for logging. Below are relevant information. What did I do wrong here?
service check
$ service jetty check
Checking arguments to Jetty:
START_INI = /opt/jetty/start.ini
START_D = /opt/jetty/start.d
JETTY_HOME = /opt/jetty
JETTY_BASE = /opt/jetty
JETTY_CONF = /opt/jetty/etc/jetty.conf
JETTY_PID = /tmp/jetty.pid
JETTY_START = /opt/jetty/start.jar
JETTY_LOGS = /opt/jetty/logs
JETTY_STATE = /opt/jetty/jetty.state
CLASSPATH =
JAVA = /usr/bin/java
JAVA_OPTIONS = -Djetty.logs=/opt/jetty/logs -Djetty.home=/opt/jetty -Djetty.base=/opt/jetty -Djava.io.tmpdir=/tmp
JETTY_ARGS = jetty.state=/opt/jetty/jetty.state jetty-started.xml
RUN_CMD = /usr/bin/java -Djetty.logs=/opt/jetty/logs -Djetty.home=/opt/jetty -Djetty.base=/opt/jetty -Djava.io.tmpdir=/tmp -jar /opt/jetty/start.jar jetty.state=/opt/jetty/jetty.state jetty-started.xml
/etc/default/jetty
$ cat /etc/default/jetty
# Defaults for jetty see /etc/init.d/jetty for more
# change to 0 to allow Jetty to start
NO_START=0
# change to 'no' or uncomment to use the default setting in /etc/default/rcS
VERBOSE=yes
# Run Jetty as this user ID (default: jetty)
# Set this to an empty string to prevent Jetty from starting automatically
JETTY_USER=jetty
# Listen to connections from this network host
# Use 0.0.0.0 as host to accept all connections.
# Uncomment to restrict access to localhost
JETTY_HOST=0.0.0.0
# The network port used by Jetty
JETTY_PORT=8080
# Timeout in seconds for the shutdown of all webapps
JETTY_SHUTDOWN=30
# Additional arguments to pass to Jetty
#JETTY_ARGS=
# Extra options to pass to the JVM
#JAVA_OPTIONS="-Xmx256m -Djava.awt.headless=true -Djava.library.path=/usr/lib"
# Home of Java installation.
JAVA=/usr/bin/java
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
JETTY_HOME=/opt/jetty
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
# defined in /etc/default/jetty). Should contain a list of space separated directories.
#JDK_DIRS="/usr/lib/jvm/default-java /usr/lib/jvm/java-6-sun"
# Java compiler to use for translating JavaServer Pages (JSPs). You can use all
# compilers that are accepted by Ant's build.compiler property.
#JSP_COMPILER=jikes
# Jetty uses a directory to store temporary files like unpacked webapps
#JETTY_TMP=/var/cache/jetty
# Jetty uses a config file to setup its boot classpath
#JETTY_START_CONFIG=/etc/jetty/start.config
# Default for number of days to keep old log files in /var/log/jetty/
#LOGFILE_DAYS=14
/opt/jetty/etc/jetty.conf
$ cat /opt/jetty/etc/jetty.conf
# ========================================================
# jetty.conf Configuration for jetty.sh script
# --------------------------------------------------------
# This file is used by the jetty.sh script to provide
# extra configuration arguments for the start.jar command
# created by that script.
#
# Each line in this file becomes an arguement to start.jar
# in addition to those found in the start.ini file
# =======================================================
#jetty-logging.xml
jetty-started.xml
/opt/jetty/modules/logging.mod
$ cat /opt/jetty/modules/logging.mod
#
# Jetty std err/out logging
#
[name]
logging
[files]
logs/
[lib]
lib/logging/*.jar
resources/
[ini-template]
## Logging Configuration
# Configure jetty logging for default internal behavior STDERR output
# -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
# Configure jetty logging for slf4j
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog
# Configure jetty logging for java.util.logging
# -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog
# STDERR / STDOUT Logging
# Number of days to retain logs
# jetty.log.retain=90
# Directory for logging output
# Either a path relative to ${jetty.base} or an absolute path
# jetty.logs=logs
/opt/jetty/resources/logback.xml
$ cat /opt/jetty/resources/logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Insert the current time formatted as "yyyyMMdd'T'HHmmss" under
the key "bySecond" into the logger context. This value will be
available to all subsequent configuration elements. -->
<timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"/>
<!-- console appender -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{100} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/opt/jetty/logs/server.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>/opt/jetty/logs/server.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{100} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.eclipse.jetty" level="INFO"/>
<logger name="org.springframework" level="INFO"/>
<logger name="org.apache" level="INFO"/>
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</configuration>
/opt/jetty/start.ini
$ cat /opt/jetty/start.ini
#===========================================================
# Jetty Startup
#
# Starting Jetty from this {jetty.home} is not recommended.
#
# A proper {jetty.base} directory should be configured, instead
# of making changes to this {jetty.home} directory.
#
# See documentation about {jetty.base} at
# http://www.eclipse.org/jetty/documentation/current/startup.html
#
# A demo-base directory has been provided as an example of
# this sort of setup.
#
# $ cd demo-base
# $ java -jar ../start.jar
#
#===========================================================
# To disable the warning message, comment the following line
--module=home-base-warning
# ---------------------------------------
# Module: server
--module=server
##
## Server Threading Configuration
##
# minimum number of threads
threads.min=10
# maximum number of threads
threads.max=200
# thread idle timeout in milliseconds
threads.timeout=60000
# buffer size for output
jetty.output.buffer.size=32768
# request header buffer size
jetty.request.header.size=8192
# response header buffer size
jetty.response.header.size=8192
# should jetty send the server version header?
jetty.send.server.version=true
# should jetty send the date header?
jetty.send.date.header=false
# What host to listen on (leave commented to listen on all interfaces)
#jetty.host=0.0.0.0
# Dump the state of the Jetty server, components, and webapps after startup
jetty.dump.start=false
# Dump the state of the Jetty server, before stop
jetty.dump.stop=false
# Enable delayed dispatch optimisation
jetty.delayDispatchUntilContent=false
# ---------------------------------------
# Module: deploy
--module=deploy
## DeployManager configuration
# Monitored Directory name (relative to jetty.base)
# jetty.deploy.monitoredDirName=webapps
# ---------------------------------------
# Module: websocket
--module=websocket
# ---------------------------------------
# Module: ext
--module=ext
# ---------------------------------------
# Module: resources
--module=resources
# ---------------------------------------
# Module: jsp
--module=jsp
# JSP Configuration
# Select JSP implementation, choices are
# glassfish : The reference implementation
# default in jetty <= 9.1
# apache : The apache version
# default jetty >= 9.2
jsp-impl=apache
# To use a non-jdk compiler for JSP compilation when using glassfish uncomment next line
# -Dorg.apache.jasper.compiler.disablejsr199=true
# ---------------------------------------
# Module: jstl
--module=jstl
# JSTL Configuration
# The glassfish jsp-impl includes JSTL by default and this module
# is not required to activate it.
# The apache jsp-impl does not include JSTL by default and this module
# is required to put JSTL on the container classpath
#
# Initialize module logging
#
--module=logging
# ---------------------------------------
# Module: http
--module=http
### HTTP Connector Configuration
-Djava.net.preferIPv4Stack=true
## HTTP port to listen on
jetty.port=8080
## HTTP idle timeout in milliseconds
http.timeout=30000
## HTTP Socket.soLingerTime in seconds. (-1 to disable)
# http.soLingerTime=-1
## Parameters to control the number and priority of acceptors and selectors
# http.selectors=1
# http.acceptors=1
# http.selectorPriorityDelta=0
# http.acceptorPriorityDelta=0
First (and most important) don't change, edit, modify, add, remove, delete, mangle, rename, touch, etc anything in ${jetty.home}
That is your jetty-distribution directory, its not meant to be changed, unpack it, then leave it alone.
It even tells you this when you startup!
2015-05-06 06:34:58.838:WARN:oejs.HomeBaseWarning:main: This instance of Jetty is not
running from a separate {jetty.base} directory, this is not recommended.
See documentation at http://www.eclipse.org/jetty/documentation/current/startup.html
2015-05-06 06:34:58.959:INFO:oejs.Server:main: jetty-9.2.10.v20150310
To fix this:
Start by creating a new directory somewhere (anywhere) this will become your ${jetty.base}
The ${jetty.base} directory is where you configure your instance of a running Jetty.
The documentation has instructions on 3 different configurations for logback in a ${jetty.base}
Just Logback
Capturing all logging events on the server side from log4j, commons-logging, slf4j, jetty log, and java.util.logging and routing them to Logback
Forcing centralized logging of all logging, even those produced in webapps, to a single logback configuration
If you follow those directions, you'll wind up with:
a ${jetty.base} that has a start.ini for you
the libraries you'll need in ${jetty.base}/lib/logging
an overridden ${jetty.base}/modules/logging.mod
the logback configuration in ${jetty.base}/resources/logback.xml
the jetty logging configuration in ${jetty.base}/resources/jetty-logging.properties
From here you setup the rest of the modules you'll need in ${jetty.base}/start.ini along with your webapps and other bits and bobs you'll need (never once editing ${jetty.home})
Finally, you'll edit your /etc/default/jetty to add a JETTY_BASE that points to this directory.
To test if this ${jetty.base} configuration makes sense, you'll use the command line.
CD into your new ${jetty.base} and run
[mybase]$ java -jar /path/to/jetty-dist/start.jar
That will start up that configuration as a normal process (not a service), from which you'll be able to see if the configuration is behaving the way you need it to.
I solved the problem by following the official example: http://eclipse.org/jetty/documentation/current/example-logging-logback-centralized.html. The actual steps are quite similar to what Joakim mentioned in his answer.
These are basically the commands I used:
[base]$ mkdir modules
[base]$ cd modules
[modules]$ curl -O https://raw.githubusercontent.com/jetty-project/logging-modules/master/capture-all/logging.mod
[modules]$ curl -O https://raw.githubusercontent.com/jetty-project/logging-modules/master/centralized/webapp-logging.mod
[modules]$ cd ..
[base]$ java -jar /opt/jetty/start.jar --add-to-start=logging,webapp-logging
Run the following command and Jetty do all the things:
[my-base]$ java -jar ../start.jar --add-to-start=logging-logback
More configuration: https://www.eclipse.org/jetty/documentation/jetty-9/index.html#configuring-logging

Log4j in tomcat not showing logs

This is my log4j.properties.
# Root logger option
log4j.rootLogger=INFO, file, stdout
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${catalina.home}\MyLog\PmcDemo.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
I am using tomcat 6.0, in my application I have used Logger from log4j yet I don't see any output on server console or in the log file. My application is using struts2 as front end, Spring framework as middle layer and hibernate as the end layer. I don't see my application logging how can I enable it in tomcat 6?
You need to switch the backslashes for forward slashes:
${catalina.home}/MyLog/PmcDemo.log
or to escape them
${catalina.home}\\MyLog\\PmcDemo.log
If that doesn't help, let us know the structure of your project and where the log4j.properties file is stored.
Try this steps,
If running Tomcat 6.x:
1. If you have not already done so, modify the <<TOMCAT_HOME>>/conf/catalina.properties file so that the shared classloader mechanism work the same as Tomcat 5.x.
2. To do this, verify that the entry beginning with shared.loader= reads shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar If running Tomcat 5.x or higher:
If running Tomcat 5.x or higher:
3. If it does not already exist, create a "shared/classes" directory under <<TOMCAT_HOME>>.
4. If it does not already exist, create a "shared/lib" directory under <<TOMCAT_HOME>>.
5. Copy log4j-###.jar into <<TOMCAT_HOME>>/shared/lib.
**Note:** Any specific version of log4j-###.jar should work. You can download the stable log4j version 1.2 installation from http://logging.apache.org/log4j/1.2/download.html
6. Copy a log4j.properties file into <<TOMCAT>>/shared/classes.
Example
To get a log file named "initiate.log" to show up in the <<TOMCAT_HOME>>/logs directory, an initial version of log4j.properties file is:
log4j.rootLogger=ERROR, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${catalina.home}/logs/initiate.log
log4j.appender.R.MaxFileSize=1000KB
log4j.appender.R.MaxBackupIndex=5
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{ABSOLUTE} 5-5p %c{2} - %m %n
log4j.logger.org.springframework=ERROR
log4j.logger.org.springframework.web.servlet.mvc=ERROR
#set to DEBUG to see hibernate and connection-pool logging output
log4j.logger.org.hibernate=ERROR
log4j.logger.org.apache.commons.dbcp=ERROR
#set to DEBUG to see Initiate-specific logging output
log4j.logger.com.initiatesystems=DEBUG
#set to DEBUG to set Initiate-specific verbose logging output
log4j.logger.verbose=ERROR
Quoted from: http://pic.dhe.ibm.com/infocenter/initiate/v9r5/index.jsp?topic=%2Fcom.ibm.datatrust.doc%2Ftopics%2Ft_datatrust_configuring_log4j_logging_apachetomcat.html

SyslogAppender not working

I have a java program and I want to log in /var/log/messages file on fedora machine. I am usin log4j SyslogAppender but its not working.
my log4j properties file contains
# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE, SYSLOG
#log4j.rootCategory=INFO, CONSOLE, LOGFILE
# Set the enterprise logger priority to DEBUG
log4j.logger.com.locaid=INFO, CONSOLE, LOGFILE, SYSLOG
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=/home/dev/app.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=[%d{dd/MM/y HH:mm:ss}][%t][%1p] %c - %m%n
log4j.appender.SYSLOG=org.apache.log4j.net.SyslogAppender
log4j.appender.SYSLOG.syslogHost=localhost
log4j.appender.SYSLOG.layout=org.apache.log4j.PatternLayout
log4j.appender.SYSLOG.layout.conversionPattern=%d{ISO8601} %-5p [%t] %c{2} %x - %m%n
log4j.appender.SYSLOG.Facility=LOCAL1
log4j.appender.SYSLOG.Threshold=debug
log4j.appender.SYSLOG.FacilityPrinting=true
in /etc/rsyslog.conf i have
local1.* /var/log/app.log
in /etc/sysconfig/rsyslog have
SYSLOGD_OPTIONS="-r -m 0 -c 4"
On restarting rsyslog service app.log file is created but no logs are being appended. I have also tried with default USER facility its not working although logger -p LOCAL1.info cmd is working and appending log to app.log. Need help.
I can't see anything wrong at the log4j end, but my /etc/default/rsyslog (on Ubuntu) says
# Options for rsyslogd
# -m 0 disables 'MARK' messages (deprecated, only used in compat mode < 3)
# -r enables logging from remote machines (deprecated, only used in compat mode < 3)
# -x disables DNS lookups on messages received with -r
# -c compatibility mode
# See rsyslogd(8) for more details
which suggests that -r and -m 0 won't work in combination with -c 4. Instead of trying to set remote access here, you should edit your /etc/rsyslogd.conf and add (or uncomment)
$ModLoad imudp
$UDPServerRun 514
#This Configuration File is used for Logger Module which is used for either using Log4J or SysLog4J
log4j.rootLogger = DEBUG,LOGFILE
#------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------
#[Log4j]
#------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------
# Log4j implements Rolling File Appender Configurations
log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender
# The log4j layout
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
# The Log4j configuration file location
log4j.appender.LOGFILE.File= C:/Documents and Settings/bgh28706/Desktop/log_output.cfg
# The Log4j conversion layout to apply for
log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %t %p %c %M %m %n
# The Log4j maximum file size to keep for before renaming to the backup file
log4j.appender.LOGFILE.MaxFileSize=5KB
# The maximum number of log4j files to be kept in the system
log4j.appender.LOGFILE.MaxBackupIndex=2
#Additivity set to False makes the output not to be produced in any other appender
log4j.additivity.LOGFILE.file=false
#------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------
#[Syslog]
#------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------
# The syslog appender to be configured for the syslog configuration to affect
log4j.appender.SYSLOGFILE=org.apache.log4j.net.SyslogAppender
# The hostname to log the syslogger information
log4j.appender.SYSLOGFILE.SyslogHost=localhost
# The facility name in the logger where the log file shall be logged
log4j.appender.SYSLOGFILE.facility=local5
# The log filename layout of the syslogger appender
log4j.appender.SYSLOGFILE.layout=org.apache.log4j.PatternLayout
# The syslogger configuration pattern
log4j.appender.SYSLOGFILE.layout.ConversionPattern=%d{ISO8601} %t %p %c %M %m %n
#Additivity set to False makes the output not to be produced in any other appender
log4j.additivity.SYSLOGFILE.file=false
See if this can help you out as it is running fine for mine!
Regards
Anand Bhat
Problem here is
SYSLOGD_OPTIONS="-r -m 0 -c 4"
Should be
SYSLOGD_OPTIONS="-r -m 0"
These options do not work together

Categories

Resources