Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't include file/line/method if empty

  • Loading branch information...
commit 0cbb2beeae3beae27afa742313ad6cec866f1731 1 parent d290186
Dmitriy Kalinin and Pieter Noordhuis authored
Showing with 12 additions and 6 deletions.
  1. +9 −3 json_codec_test.go
  2. +3 −3 record.go
View
12 json_codec_test.go
@@ -27,9 +27,6 @@ func (s *JsonCodecSuite) TestJsonCodec(c *C) {
"log_level",
"message",
"data",
- "file",
- "line",
- "method",
}
for _, f := range fields {
@@ -43,3 +40,12 @@ func (s *JsonCodecSuite) TestTimestampIsFormattedAsFloat(c *C) {
c.Assert(err, IsNil)
c.Assert(string(m), Matches, `.*"timestamp":\d{10}\.\d{9},.*`)
}
+
+func (s *JsonCodecSuite) TestEmptyFileLineMethodNotIncluded(c *C) {
+ r := NewRecord("source", LOG_INFO, "Hello world", nil)
+ m, err := s.EncodeRecord(r)
+ c.Assert(err, IsNil)
+ c.Check(string(m), Not(Matches), `.*"file":.*`)
+ c.Check(string(m), Not(Matches), `.*"line":.*`)
+ c.Check(string(m), Not(Matches), `.*"method":.*`)
+}
View
6 record.go
@@ -21,9 +21,9 @@ type Record struct {
Level LogLevel `json:"log_level"`
Message string `json:"message"`
Data map[string]interface{} `json:"data"`
- File string `json:"file"`
- Line int `json:"line"`
- Method string `json:"method"`
+ File string `json:"file,omitempty"`
+ Line int `json:"line,omitempty"`
+ Method string `json:"method,omitempty"`
}
var pid int
Please sign in to comment.
Something went wrong with that request. Please try again.