Skip to content

Commit 10209ba

Browse files
committed
Add template for output
1 parent 2df5865 commit 10209ba

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

etc/go-syslog.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ syslog:
55
perms: 0666
66
filter:
77
facility: "auth,authpriv"
8+
output:
9+
template: "[SYSLOG] %s"
810

911
pipes:
1012
-
@@ -15,3 +17,5 @@ pipes:
1517
path: /docker.stderr
1618
type: stderr
1719
perms: 0666
20+
output:
21+
template: "[STDERR] %s"

pipe.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ type Pipe struct {
1313
Path string
1414
Type string
1515
Perms string
16+
17+
Output struct {
18+
Template string
19+
}
1620
}
1721

1822
// Create and handle log data from pipe
1923
func handlePipe(pipe Pipe) {
2024
pipeExists := false
2125

22-
LoggerStdout.Verbose(fmt.Sprintf(" -> Starting named pipe (%s)", pipe.Path))
26+
LoggerStdout.Verbose(fmt.Sprintf(" -> starting named pipe (%s)", pipe.Path))
2327

2428
// get pipe permissions
2529
if pipe.Perms == "" {
@@ -63,11 +67,16 @@ func handlePipe(pipe Pipe) {
6367
}
6468

6569
if message != "" {
70+
71+
if pipe.Output.Template != "" {
72+
message = fmt.Sprintf(pipe.Output.Template, message)
73+
}
74+
6675
switch pipe.Type {
6776
case "stdout":
68-
LoggerStdout.Println(message)
77+
LoggerStdout.Print(message)
6978
case "stderr":
70-
LoggerStderr.Println(message)
79+
LoggerStderr.Print(message)
7180
}
7281
}
7382
}

syslog.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ type Syslog struct {
1313
Facility string
1414
facility int
1515
}
16+
Output struct {
17+
Template string
18+
}
1619
}
1720

1821

@@ -53,7 +56,7 @@ var SyslogFacilityLookup = map[int]string {
5356
}
5457

5558
func handleSyslog() {
56-
LoggerStdout.Verbose(fmt.Sprintf(" -> Starting syslog daemon (%s)", configuration.Syslog.Path))
59+
LoggerStdout.Verbose(fmt.Sprintf(" -> starting syslog daemon (%s)", configuration.Syslog.Path))
5760

5861
// Check if syslog path exists, remove if already existing
5962
_, err := os.Stat(configuration.Syslog.Path)
@@ -77,13 +80,14 @@ func handleSyslog() {
7780
continue
7881
}
7982

80-
facilityId := logParts["facility"].(int)
81-
facility := "custom"
82-
if val, ok := SyslogFacilityLookup[facilityId]; ok {
83-
facility = val
83+
// build message
84+
message := logParts["content"]
85+
86+
// custom template
87+
if configuration.Syslog.Output.Template != "" {
88+
message = fmt.Sprintf(configuration.Syslog.Output.Template, message)
8489
}
8590

86-
message := fmt.Sprintf("%s: %s", facility, logParts["content"])
8791
LoggerStdout.Println(message)
8892
}
8993
}(channel)

0 commit comments

Comments
 (0)