-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #18712. Add rfc5424 log format for syslog.
Previously docker used obsolete rfc3164 syslog format for syslog. rfc3164 explicitly uses semicolon as a separator between 'TAG' and 'Content' section of the log message. Docker uses semicolon as a separator between image name and version tag. When {{.ImageName}} was used as a tag expression and contained ":" syslog parser mistreated "tag" part of the image name as syslog message body, which resulted in incorrect "syslogtag" been reported by syslog daemon. Use of rfc5424 log format partually fixes the issue as it does not use semicolon as a separator. However using default rfc5424 syslog format itroduces backward incompatability because rsyslog template keyword %syslogtag% is parsed differently. In rfc3164 it uses the "TAG" part reported before the "pid" part. In rfc5424 it uses "appname" part reported before the pid part, while tag part is introduced by %msgid% part. For more information on rsyslog configuration properties see: http://www.rsyslog.com/doc/master/configuration/properties.html Added two options to specify logging in either rfc5424, rfc3164 format or unix format omitting hostname in order to keep backwards compatability with previous versions. Signed-off-by: Solganik Alexander <[email protected]>
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// +build linux | ||
|
||
package syslog | ||
|
||
import ( | ||
syslog "github.com/RackSec/srslog" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func functionMatches(expectedFun interface{}, actualFun interface{}) bool { | ||
return reflect.ValueOf(expectedFun).Pointer() == reflect.ValueOf(actualFun).Pointer() | ||
} | ||
|
||
func TestParseLogFormat(t *testing.T) { | ||
formatter, framer, err := parseLogFormat("rfc5424") | ||
if err != nil || !functionMatches(rfc5424formatterWithAppNameAsTag, formatter) || | ||
!functionMatches(syslog.RFC5425MessageLengthFramer, framer) { | ||
t.Fatal("Failed to parse rfc5424 format", err, formatter, framer) | ||
} | ||
|
||
formatter, framer, err = parseLogFormat("rfc3164") | ||
if err != nil || !functionMatches(syslog.RFC3164Formatter, formatter) || | ||
!functionMatches(syslog.DefaultFramer, framer) { | ||
t.Fatal("Failed to parse rfc3164 format", err, formatter, framer) | ||
} | ||
|
||
formatter, framer, err = parseLogFormat("") | ||
if err != nil || !functionMatches(syslog.UnixFormatter, formatter) || | ||
!functionMatches(syslog.DefaultFramer, framer) { | ||
t.Fatal("Failed to parse empty format", err, formatter, framer) | ||
} | ||
|
||
formatter, framer, err = parseLogFormat("invalid") | ||
if err == nil { | ||
t.Fatal("Failed to parse invalid format", err, formatter, framer) | ||
} | ||
} | ||
|
||
func TestValidateLogOptEmpty(t *testing.T) { | ||
emptyConfig := make(map[string]string) | ||
if err := ValidateLogOpt(emptyConfig); err != nil { | ||
t.Fatal("Failed to parse empty config", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters