Skip to content

Commit

Permalink
Convert to the correct logging severity.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Jul 1, 2016
1 parent eff592c commit 664a6e7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
6 changes: 3 additions & 3 deletions logfwd/syslog/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ func messageFromRecord(rec logfwd.Record) (rfc5424.Message, error) {
case loggo.ERROR:
msg.Priority.Severity = rfc5424.SeverityError
case loggo.WARNING:
msg.Priority.Severity = rfc5424.SeverityError
msg.Priority.Severity = rfc5424.SeverityWarning
case loggo.INFO:
msg.Priority.Severity = rfc5424.SeverityError
msg.Priority.Severity = rfc5424.SeverityInformational
case loggo.DEBUG, loggo.TRACE:
msg.Priority.Severity = rfc5424.SeverityError
msg.Priority.Severity = rfc5424.SeverityDebug
default:
return msg, errors.Errorf("unsupported log level %q", rec.Level)
}
Expand Down
40 changes: 39 additions & 1 deletion logfwd/syslog/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *ClientSuite) TestClose(c *gc.C) {
s.stub.CheckCallNames(c, "Close")
}

func (s *ClientSuite) TestSend(c *gc.C) {
func (s *ClientSuite) TestSendLogFull(c *gc.C) {
tag := names.NewMachineTag("99")
cID := "9f484882-2f18-4fd2-967d-db9663db7bea"
mID := "deadbeef-2f18-4fd2-967d-db9663db7bea"
Expand Down Expand Up @@ -145,6 +145,44 @@ func (s *ClientSuite) TestSend(c *gc.C) {
})
}

func (s *ClientSuite) TestSendLogLevels(c *gc.C) {
tag := names.NewMachineTag("99")
cID := "9f484882-2f18-4fd2-967d-db9663db7bea"
mID := "deadbeef-2f18-4fd2-967d-db9663db7bea"
ver := version.MustParse("1.2.3")
rec := logfwd.Record{
Origin: logfwd.OriginForMachineAgent(tag, cID, mID, ver),
Timestamp: time.Unix(12345, 0),
Level: loggo.ERROR,
Location: logfwd.SourceLocation{
Module: "juju.x.y",
Filename: "x/y/spam.go",
Line: 42,
},
Message: "(╯°□°)╯︵ ┻━┻",
}
client := syslog.Client{Sender: s.sender}

levels := map[loggo.Level]rfc5424.Severity{
loggo.ERROR: rfc5424.SeverityError,
loggo.WARNING: rfc5424.SeverityWarning,
loggo.INFO: rfc5424.SeverityInformational,
loggo.DEBUG: rfc5424.SeverityDebug,
loggo.TRACE: rfc5424.SeverityDebug,
}
for level, expected := range levels {
c.Logf("trying %s -> %s", level, expected)
s.stub.ResetCalls()
rec.Level = level

err := client.Send(rec)
c.Assert(err, jc.ErrorIsNil)

msg := s.stub.Calls()[0].Args[0].(rfc5424.Message)
c.Check(msg.Severity, gc.Equals, expected)
}
}

type stubSenderOpener struct {
stub *testing.Stub

Expand Down

0 comments on commit 664a6e7

Please sign in to comment.