Permalink
Browse files

Change JsonPrettifier to implement Codec interface

PrettifyEntry already has the EncodeRecord signature,
by renaming we can use like so:
  out := steno.NewIOSink(os.Stdout)
  out.SetCodec(steno.NewJsonPrettifier(steno.EXCLUDE_NONE))

Changed Init() to only set default Sink Codec if nil

Change-Id: I80a56a92a2ef1a820055d3c5ff559de9b19a68cc
  • Loading branch information...
1 parent 7524d17 commit a3a577a2048f42b8206bb5415bbefb4b7461323b @dougm dougm committed Sep 28, 2012
Showing with 10 additions and 8 deletions.
  1. +1 −1 json_prettifier.go
  2. +6 −6 json_prettifier_test.go
  3. +3 −1 steno.go
View
@@ -71,7 +71,7 @@ func (p *JsonPrettifier) DecodeJsonLogEntry(logEntry string) (*Record, error) {
return record, err
}
-func (p *JsonPrettifier) PrettifyEntry(record *Record) ([]byte, error) {
+func (p *JsonPrettifier) EncodeRecord(record *Record) ([]byte, error) {
buffer := bytes.NewBufferString("")
err := p.entryTemplate.Execute(buffer, record)
return buffer.Bytes(), err
View
@@ -21,27 +21,27 @@ func (s *JsonPrettifierSuite) TestConstOrder(c *C) {
record := NewRecord(LOG_INFO, "Hello, world", map[string]string{"foo": "bar"})
prettifier1 := NewJsonPrettifier(EXCLUDE_FILE | EXCLUDE_DATA)
- bytes1, _ := prettifier1.PrettifyEntry(record)
+ bytes1, _ := prettifier1.EncodeRecord(record)
prettifier2 := NewJsonPrettifier(EXCLUDE_DATA | EXCLUDE_FILE)
- bytes2, _ := prettifier2.PrettifyEntry(record)
+ bytes2, _ := prettifier2.EncodeRecord(record)
c.Assert(string(bytes1), Equals, string(bytes2))
}
-func (s *JsonPrettifierSuite) TestPrettifyEntry(c *C) {
+func (s *JsonPrettifierSuite) TestEncodeRecord(c *C) {
config.EnableLOC = true
record := NewRecord(LOG_INFO, "Hello, world", map[string]string{"foo": "bar"})
config.EnableLOC = false
l := record.Line
prettifier := NewJsonPrettifier(EXCLUDE_NONE)
- b, err := prettifier.PrettifyEntry(record)
+ b, err := prettifier.EncodeRecord(record)
c.Assert(err, IsNil)
// One example:
- // INFO 2012-09-27 16:53:40 json_prettifier_test.go:34:TestPrettifyEntry {"foo":"bar"} Hello, world
- c.Assert(string(b), Matches, fmt.Sprintf(`INFO .*son_prettifier_test.go:%d:TestPrettifyEntry.*{"foo":"bar"}.*Hello, world`, l))
+ // INFO 2012-09-27 16:53:40 json_prettifier_test.go:34:TestEncodeRecord {"foo":"bar"} Hello, world
+ c.Assert(string(b), Matches, fmt.Sprintf(`INFO .*son_prettifier_test.go:%d:TestEncodeRecord.*{"foo":"bar"}.*Hello, world`, l))
}
func (s *JsonPrettifierSuite) TestDecodeLogEntry(c *C) {
View
@@ -28,7 +28,9 @@ func Init(c *Config) {
}
for _, sink := range config.Sinks {
- sink.SetCodec(config.Codec)
+ if sink.GetCodec() == nil {
+ sink.SetCodec(config.Codec)
+ }
}
if config.Port > 0 {

0 comments on commit a3a577a

Please sign in to comment.