You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Tukesh (Jira)" <ji...@apache.org> on 2022/01/19 13:05:00 UTC
[jira] [Reopened] (LOG4J2-3238) Log4j 1.2 bridge API doesn't write the messages to rsyslog in proper "PatternLayout" mentioned in log4j.properties file when SysLogAppender is used
[ https://issues.apache.org/jira/browse/LOG4J2-3238?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tukesh reopened LOG4J2-3238:
----------------------------
{{I think "org.apache.log4j.net.SyslogAppender" }}should work with bridge API when compatibility flag is set to true.
*java -Dlog4j1.compatibility=true -jar Example.jar*
*log4j.properties contents :-*
log4j.rootLogger=DEBUG,syslog,file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/tmp/logigng.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=Main[%pid] :%t: %c %-4p - %m\n
log4j.appender.syslog=org.apache.log4j.net.SyslogAppender
log4j.appender.syslog.Threshold=DEBUG
log4j.appender.syslog.syslogHost=localhost
log4j.appender.syslog.port=9999
log4j.appender.syslog.header=true
log4j.appender.syslog.Facility=LOCAL3
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
log4j.appender.syslog.layout.conversionPattern=Main[%pid] :%t: %c %-4p - %m\n
*File appender is logging message is proper format like :-*
Main[19666] :main: test.logger.LoggerExample DEBUG - Log4j-shell this is a debug message
Main[19666] :main: test.logger.LoggerExample DEBUG - Log4j-shell this is a debug message
Main[19666] :main: test.logger.LoggerExample DEBUG - Log4j-shell this is a debug message
Main[19666] :main: test.logger.LoggerExample DEBUG - Log4j-shell this is a debug message
*_where as syslog appender is not logging message in proper format :-_*
Debug line with all properties:
FROMHOST: 'localhost.localdomain', fromhost-ip: '127.0.0.1', HOSTNAME: 'Log4j-shell', PRI: 13,
syslogtag 'this', programname: 'this', APP-NAME: 'this', PROCID: '-', MSGID: '-',
TIMESTAMP: 'Jan 19 18:28:13', STRUCTURED-DATA: '-',
msg: ' is a debug message'
escaped msg: ' is a debug message'
inputname: imtcp rawmsg: 'Log4j-shell this is a debug message'
$!:
$.:
$/:
> Log4j 1.2 bridge API doesn't write the messages to rsyslog in proper "PatternLayout" mentioned in log4j.properties file when SysLogAppender is used
> -----------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: LOG4J2-3238
> URL: https://issues.apache.org/jira/browse/LOG4J2-3238
> Project: Log4j 2
> Issue Type: Bug
> Components: API, Appenders, Core, Pattern Converters
> Affects Versions: 2.16.0
> Environment: *JDK .1.8 :-*
> copy-jdk-configs-3.3-10.el7_5.noarch
> java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.i686
> java-1.8.0-openjdk-devel-1.8.0.242.b08-0.el7_7.i686
> java-1.8.0-openjdk-headless-1.8.0.242.b08-0.el7_7.i686
> *JVM arguments :-*
> *-Dlog4j1.compatibility=true*
>
> *Jar used :-*
> log4j-1.2-api-2.16.0.jar
> log4j-api-2.16.0.jar
> log4j-core-2.16.0.jar
> Reporter: Tukesh
> Priority: Blocker
> Attachments: log4j2.tar.gz
>
>
> Log4j 1.2 bridge API doesn't write the messages to rsyslog in proper "PatternLayout" mentioned in log4j.properties file when SysLogAppender is used .
> You can see log messages are missing Conversion Patterns effect like string "MyMain" , Data, ClassName etc.
>
> log4j.properties file :-
>
> {code:java}
> log4j.rootLogger=DEBUG,SYSLOG
> log4j.appender.SYSLOG=org.apache.log4j.net.SyslogAppender
> log4j.appender.SYSLOG.Threshold=DEBUG
> log4j.appender.SYSLOG.syslogHost=localhost
> log4j.appender.SYSLOG.port=514
> log4j.appender.SYSLOG.header=true
> log4j.appender.SYSLOG.Facility=LOCAL3
> log4j.appender.SYSLOG.layout=org.apache.log4j.PatternLayout
> log4j.appender.SYSLOG.layout.conversionPattern=MyMain[%pid] :%t: %c %-4p %m%n
> {code}
>
>
> *Source code ( LoggerExample.java ) :-*
>
>
> {code:java}
> package test.logger;
> import org.apache.log4j.Logger;
> import java.io.*;
> import java.sql.SQLException;
> import java.util.concurrent.TimeUnit;
> public class LoggerExample{
> static Logger log = Logger.getLogger(LoggerExample.class.getName());
> public static void main(String[] args)throws IOException,SQLException{
> log.debug("log4j-shell Starting...");
> while(true){
> System.out.println("I'm running...");
> log.debug("Test Log4j-shell this is a debug message");
> try {
> TimeUnit.SECONDS.sleep(1);
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> }
> }
> }
> {code}
>
>
> *Sample message created :-*
>
> {code:java}
>
> log4j-shell Starting...
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
> Test Log4j-shell this is a debug message
>
> {code}
>
>
>
--
This message was sent by Atlassian Jira
(v8.20.1#820001)