Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 761
Abhishek bhutra Avatar asked Sep 19 '12 07:09

Abhishek bhutra


2 Answers

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
like image 148
Ian Roberts Avatar answered Nov 07 '22 09:11

Ian Roberts


#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

like image 2
Anand Builders Avatar answered Nov 07 '22 09:11

Anand Builders