Skip to content

Commit

Permalink
Merge pull request #1529 from hashicorp/issue-1523-syslog-fix
Browse files Browse the repository at this point in the history
Issue 1523 syslog fix
  • Loading branch information
eikenb authored Nov 1, 2021
2 parents a009fea + 9f4a0ed commit 1402218
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
5 changes: 4 additions & 1 deletion logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ func (writer logWriter) Write(bytes []byte) (int, error) {
if len(bytes) == 0 {
return 0, nil
}
return fmt.Fprintf(writer.out, "%s %s", now(), bytes)
if _, err := fmt.Fprintf(writer.out, "%s %s", now(), bytes); err != nil {
return 0, err
}
return len(bytes), nil
}

// Config is the configuration for this log setup.
Expand Down
13 changes: 10 additions & 3 deletions logging/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ func TestWriter(t *testing.T) {
config := newConfig(&buf)
writer, err := newWriter(config)
if err != nil {
t.Fatal(err)
t.Error(err)
}
n, err := writer.Write([]byte(tc.input))
if err != nil {
t.Error(err)
}
if n != len(tc.input) {
t.Errorf("byte count (%d) doesn't match output len (%d).",
n, len(tc.input))
}
writer.Write([]byte(tc.input))
if buf.String() != tc.output {
t.Fatalf("unexpected log output string: '%s'", buf.String())
t.Errorf("unexpected log output string: '%s'", buf.String())
}
}

Expand Down
8 changes: 7 additions & 1 deletion logging/syslog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ func TestSyslogFilter(t *testing.T) {
}

s := &SyslogWrapper{l, filt}
n, err := s.Write([]byte("[INFO] test"))
infotest := []byte("[INFO] test")
n, err := s.Write(infotest)
if err != nil {
t.Fatalf("err: %s", err)
}
if n == 0 {
t.Fatalf("should have logged")
}
if n != len(infotest) {
t.Fatalf("byte count (%d) doesn't match output len (%d).",
n, len(infotest))

}

n, err = s.Write([]byte("[DEBUG] test"))
if err != nil {
Expand Down

0 comments on commit 1402218

Please sign in to comment.