Permalink
Browse files

Use lowercase field names in JSON codec

  • Loading branch information...
1 parent b878f67 commit 949de95e7094e24b99004b6c169495e701ef40d8 @pietern pietern committed Jan 29, 2013
Showing with 34 additions and 14 deletions.
  1. +25 −4 json_codec_test.go
  2. +9 −10 record.go
View
29 json_codec_test.go
@@ -1,17 +1,38 @@
package steno
import (
+ "fmt"
. "launchpad.net/gocheck"
)
type JsonCodecSuite struct {
+ JsonCodec
}
var _ = Suite(&JsonCodecSuite{})
func (s *JsonCodecSuite) TestJsonCodec(c *C) {
- record := NewRecord("source", LOG_INFO, "Hello world", map[string]string{})
- codec := NewJsonCodec()
- msg, _ := codec.EncodeRecord(record)
- c.Assert(string(msg), Matches, `{.*"Message":"Hello world".*}`)
+ r := NewRecord("source", LOG_INFO, "Hello world", map[string]string{})
+ m, err := s.EncodeRecord(r)
+ c.Assert(err, IsNil)
+
+ // The names of these fields are a direct copy of the fields used by the Ruby
+ // version of steno to prevent breaking the prettifiers. Some of these fields
+ // can be changed (e.g. `process_id` -> `pid`, `log_level` -> `level), but
+ // only as long as the prettifiers are also updated.
+ fields := []string{
+ "timestamp",
+ "process_id",
+ "source",
+ "log_level",
+ "message",
+ "data",
+ "file",
+ "line",
+ "method",
+ }
+
+ for _, f := range fields {
+ c.Check(string(m), Matches, fmt.Sprintf(`{.*"%s":.*}`, f))
+ }
}
View
19 record.go
@@ -7,17 +7,16 @@ import (
"time"
)
-// FIXME: Missing fields
type Record struct {
- Timestamp float64
- Pid int
- Source string
- Level LogLevel
- Message string
- Data map[string]string
- File string
- Line int
- Method string
+ Timestamp float64 `json:"timestamp"`
+ Pid int `json:"process_id"`
+ Source string `json:"source"`
+ Level LogLevel `json:"log_level"`
+ Message string `json:"message"`
+ Data map[string]string `json:"data"`
+ File string `json:"file"`
+ Line int `json:"line"`
+ Method string `json:"method"`
}
var pid int

0 comments on commit 949de95

Please sign in to comment.