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
Related
I using jetty as my container and I set up solr inside it, I using log4j.properties for my logging,when I used jetty standalone I can see my jetty logs ,but when I using solr an d log4j I only see solr.log file that all my jetty and solr logs are mixed in it,and my jetty.logs file created at the same time but it is empty,how can I separate the solr and jetty logs?
this is my log4j.properties:
# Logging level
solr.log=logs
log4j.rootLogger=INFO, file, CONSOLE
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 [%X{collection} %X{shard} %X{replica} %X{core}] \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=${solr.log}/solr.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%-5p - %d{yyyy-MM-dd HH:mm:ss.SSS}; [%X{collection} %X{shard} %X{replica} %X{core}] %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
This is how you can separate Solr and Jetty logs and write them into separate files using additivity:
log4j.additivity.org.apache.solr=false
log4j.additivity.org.eclipse=false
log4j.logger.org.apache.solr=INFO, SOLR
log4j.logger.org.eclipse=INFO, JETTY
I have a webservice program which has multiple classes talking to each other.
After running the program using tomcat in eclipse, I copy the wsdl url in soap UI to test it out and if there's any exception then it has to be in printed in a log file as I am file appender logic from log4j. Spent almost three days with no luck
Here is log4j.properties file:
# Define the root logger with appender file
log4j.rootLogger = DEBUG, FILE, theConsoleAppender
log4j.category.com.wataniya.Wataniya_WebServiceSkeleton=DEBUG, FILE
### direct log messages to stdout ###
log4j.appender.theConsoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.theConsoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.theConsoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
# Set the name of the file
log4j.appender.FILE.File=log.txt
# 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=true
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern= %d{dd MMM yyyy HH:mm:ss,SSS} %c %p %t %m%n%n
Imported the required jar files in to build path in eclipse. More info can be found at this link in importing the jar files and configuring the properties file: Link
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
First off, I apologize if this question has already been asked. I searched but couldn't find anything specific to my problem.
Here's the scenario -
I'm deploying an application, say, MyFirstWebApp in Tomcat 6.0.35.
Tomcat has a log4j.properties in it's common loader path which looks like -
log4j.rootLogger=INFO, LOGFILE
log4j.logger.com.test.java=DEBUG, TEST
log4j.additivity.com.test.java=false
# 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=[%p] %m%n
# LOGFILE is set to be a File appender using a PatternLayout
log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.LOGFILE.File=/home/myuserid/tomcat.log
log4j.appender.LOGFILE.MaxFileSize=25MB
log4j.appender.LOGFILE.MaxBackupIndex=5
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d %p %t %c - %m%n
# LOGFILE is set to be a File appender using a PatternLayout
log4j.appender.TEST=org.apache.log4j.FileAppender
log4j.appender.TEST.File=/home/myuserid/test.log
log4j.appender.TEST.layout=org.apache.log4j.PatternLayout
log4j.appender.TEST.layout.ConversionPattern=%d %p %t %c - %m%n
Tomcat also has a log4j.jar file in it's lib/ directory.
Now, MyFirstWebApp has a log4j.properties inside it's WEB-INF/classes directory. MyFirstWebApp also has a log4j.jar in it's WEB-INF/lib directory.
MyFirstWebApp log4j.properties looks like this -
log4j.rootCategory=INFO,LOGFILE
# Set the enterprise logger priority to FATAL
log4j.logger.com.test=INFO
# 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=[%p] %m%n
# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.LOGFILE.MaxFileSize=10MB
log4j.appender.LOGFILE.MaxBackupIndex=99
log4j.appender.LOGFILE.File=/home/myuserid/mywebapp.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
When I start the server and deploy this application, I expected to find 3 log files - tomcat.log, test.log and mywebapp.log (which I did).
I also expected to find all logging from "com.test.java" package inside "test.log" but they were found in "mywebapp.log"
What am I doing wrong here? How can I log messages from "com.test.java" without modifying MyFirstWebApp?
The log4j.properties file is loaded by the classloader. All the classes in your webapp use the webapp's classloader, and thus only see the log4j.properties file that is under WEB-INF/classes. And thus, the logs from com.test.java that are generated by classes of your webapp use the configuration found in WEB-INF/classes/log4j.properties. So they're written to mywebapp.log.
If you want the logs from com.test.java to go to test.log, you'll have to either modify the webapp's log4j.properties (right solution), or to put those classes out of the webapp, directly in tomcat's classpath (but don't do this).
I am running REST web service on Tomacat 6.0.32. I am using log4j API to log errors or anything else.
Basically you only need to include this line of code
static Logger logger = Logger.getLogger(TestLogging.class.getName());
logger.debug("String blah blah");
I run main method to test if it is working. So, the program writes log info into text file and on the console of NetBeans.
But if you deploy the project and then run it on the browser those logs do not appear no where; neither on console nor text file nor on Tomcat's logs.
The following is properties file:
# Set root category priority to DEBUG and set its only appender to A1
log4j.rootCategory=DEBUG, A1, file
log4j.additivity.logger=false
# A1 is set to be a ConsoleAppender (writes to system console).
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%p [%t] %F %L %x - %m%n
#### Second appender writes to a file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=eMart_logger.log
# Control the maximum log file size
log4j.appender.file.MaxFileSize=1MB
# Archive log files (one backup file here)
log4j.appender.R.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%p %d %t %F %L - %m%n
What is the problem?
Cheers
Use a FileAppender to get it to log to a file when you are running on a server.
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/FileAppender.html