Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove obsolete TaggedLogger

  • Loading branch information...
commit 71cc65fc0eb310d522ce33a93f31a33fb670ef4f 1 parent b5e9451
Pieter Noordhuis and Tim Labeeuw authored
Showing with 9 additions and 101 deletions.
  1. +9 −7 perf_test.go
  2. +0 −36 tagged_logger.go
  3. +0 −58 tagged_logger_test.go
View
16 perf_test.go
@@ -6,6 +6,7 @@ import (
func BenchmarkNoSink(b *testing.B) {
Init(&Config{})
+
loggers = make(map[string]*BaseLogger)
logger := NewLogger("nosink")
@@ -16,6 +17,7 @@ func BenchmarkDevNullSink(b *testing.B) {
Init(&Config{
Sinks: []Sink{NewFileSink("/dev/null")},
})
+
loggers = make(map[string]*BaseLogger)
logger := NewLogger("dev_null_sink")
@@ -27,22 +29,22 @@ func BenchmarkDevNullSinkWithLOC(b *testing.B) {
Sinks: []Sink{NewFileSink("/dev/null")},
EnableLOC: true,
})
+
loggers = make(map[string]*BaseLogger)
logger := NewLogger("dev_null_sink_with_loc")
performBenchmark(logger, b)
}
-func BenchmarkTaggedLoggerInDevNullSink(b *testing.B) {
+func BenchmarkDevNullSinkWithData(b *testing.B) {
Init(&Config{
Sinks: []Sink{NewFileSink("/dev/null")},
})
+
loggers = make(map[string]*BaseLogger)
- tags := map[string]interface{}{
- "thread_id": "1234",
- "program_name": "benchmark",
- }
- logger := NewTaggedLogger(NewLogger("dev_null_sink_tagged"), tags)
+ logger := NewLogger("dev_null_sink_with_data")
+ logger.Set("key1", "value1")
+ logger.Set("key2", "value2")
performBenchmark(logger, b)
}
@@ -50,6 +52,6 @@ func BenchmarkTaggedLoggerInDevNullSink(b *testing.B) {
func performBenchmark(logger *Logger, b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
- logger.Fatal("Hello, world.")
+ logger.Info("Hello, world.")
}
}
View
36 tagged_logger.go
@@ -1,36 +0,0 @@
-package steno
-
-type TaggedLogger struct {
- *Logger
-
- d map[string]interface{}
-}
-
-func NewTaggedLogger(l *Logger, d map[string]interface{}) *Logger {
- tl := &TaggedLogger{
- Logger: l,
- d: d,
- }
-
- return &Logger{L: tl}
-}
-
-func (l *TaggedLogger) Log(x LogLevel, m string, d map[string]interface{}) {
- if d != nil {
- e := make(map[string]interface{})
-
- // Copy the logger's data
- for k, v := range l.d {
- e[k] = v
- }
-
- // Overwrite specified data
- for k, v := range d {
- e[k] = v
- }
-
- l.Logger.Log(x, m, e)
- } else {
- l.Logger.Log(x, m, l.d)
- }
-}
View
58 tagged_logger_test.go
@@ -1,58 +0,0 @@
-package steno
-
-import (
- . "launchpad.net/gocheck"
-)
-
-type TaggedLoggerSuite struct {
- nSink *nullSink
-}
-
-var _ = Suite(&TaggedLoggerSuite{})
-
-func (s *TaggedLoggerSuite) SetUpTest(c *C) {
- s.nSink = newNullSink()
-
- cfg := Config{}
- cfg.Sinks = []Sink{s.nSink}
- Init(&cfg)
- loggers = make(map[string]*BaseLogger)
-}
-
-func (s *TaggedLoggerSuite) TearDownTest(c *C) {
- s.nSink = nil
-
- config = Config{}
- loggers = nil
- loggerRegexp = nil
- loggerRegexpLevel = nil
-}
-
-func (s *TaggedLoggerSuite) TestNewTaggedLogger(c *C) {
- logger := NewLogger("foobar")
- taggedLogger := NewTaggedLogger(logger, map[string]interface{}{"foo": "bar"})
- taggedLogger.Info("Hello")
- taggedLogger.Debug("World")
- // the level of tagged logger should be the same as the derived logger
- c.Assert(s.nSink.records, HasLen, 1)
-}
-
-func (s *TaggedLoggerSuite) TestTaggedLogger(c *C) {
- logger := NewLogger("foobar")
- taggedLogger := NewTaggedLogger(logger, map[string]interface{}{"foo": "bar"})
- taggedLogger.Info("Hello")
- bytes, _ := config.Codec.EncodeRecord(s.nSink.records[0])
- c.Assert(string(bytes), Matches, `{.*"foo":"bar".*}`)
-}
-
-func (s *TaggedLoggerSuite) TestTaggedLogger2(c *C) {
- logger := NewLogger("whatever")
- taggedLogger := NewTaggedLogger(logger, map[string]interface{}{"foo": "bar"})
- taggedLogger2 := NewTaggedLogger(taggedLogger, map[string]interface{}{"oof": "rab"})
- taggedLogger2.Info("Hello")
- c.Assert(s.nSink.records, HasLen, 1)
-
- bytes, _ := config.Codec.EncodeRecord(s.nSink.records[0])
- c.Assert(string(bytes), Matches, `{.*"foo":"bar".*}`)
- c.Assert(string(bytes), Matches, `{.*"oof":"rab".*}`)
-}
Please sign in to comment.
Something went wrong with that request. Please try again.