logging-log4net-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Becker (JIRA)" <j...@apache.org>
Subject [jira] [Created] (LOG4NET-458) LocalSyslogAppender does not support multiple identities
Date Tue, 17 Mar 2015 16:37:38 GMT
Christian Becker created LOG4NET-458:
----------------------------------------

             Summary: LocalSyslogAppender does not support multiple identities
                 Key: LOG4NET-458
                 URL: https://issues.apache.org/jira/browse/LOG4NET-458
             Project: Log4net
          Issue Type: Bug
          Components: Appenders
    Affects Versions: 1.2.13
            Reporter: Christian Becker


With multiple LocalSyslogAppender where each one has a different identity, everything just
gets logged with the identity of the last Appender.

In the example below, every log message has the identity of task_info_syslog, even the appender
used is rts_syslog.

I checked the code and this is a bug in LocalSyslogAppender.Append(). 

The syslogtag is not part of the syslog() function call, but has to be done using openlog()
and after a call to openlog(), the identity set is used for all subsequent syslog() calls.

A call to openlog() is only done once in ActivateOptions() and never again, this causes the
observed behavior, that the last instance of LocalSyslogAppender wins. 

A possible fix for this is to add a call to openlog() in Append() before calling syslog(),
like:

{code}
diff --git a/LocalSyslogAppender.cs b/LocalSyslogAppender.cs
--- a/LocalSyslogAppender.cs
+++ b/LocalSyslogAppender.cs
@@ -387,6 +387,8 @@ namespace log4net.Appender
             int priority = GeneratePriority(m_facility, GetSeverity(loggingEvent.Level));
             string message = RenderLoggingEvent(loggingEvent);

+            // Call libc openlog() first to ensure correct identity and facility is set
+            openlog(m_handleToIdentity, 1, m_facility);
             // Call the local libc syslog method
             // The second argument is a printf style format string
             syslog(priority, "%s", message);
{code}

Here is our config for reference:

{code}
[...]
<appender name="rts_syslog" type="log4net.Appender.LocalSyslogAppender">
  <facility value="User" />
  <identity type="log4net.Util.PatternString" value="foobar/dev/dev1/rts" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss}, %level, %message%newline" />
  </layout>
</appender>
[...]
<appender name="task_info_syslog" type="log4net.Appender.LocalSyslogAppender">
  <facility value="User" />
  <identity type="log4net.Util.PatternString" value="foobar/dev/dev1/task-info" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss}, %level, %message%newline" />
  </layout>
</appender>
[...]
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message