Skip to content

Commit

Permalink
Merge pull request #45 from hmlanigan/get-logger-with-labels
Browse files Browse the repository at this point in the history
#45

Add GetLoggerWithLabels function, missing from original add of labels for loggers.
  • Loading branch information
jujubot authored Jul 28, 2021
2 parents abb62bf + 36ef2af commit eebad3a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions global.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func GetLogger(name string) Logger {
return defaultContext.GetLogger(name)
}

// GetLogger returns a Logger for the given module name with the correct
// assiciated labels, creating it and its parents if necessary.
func GetLoggerWithLabels(name string, labels ...string) Logger {
return defaultContext.GetLogger(name, labels...)
}

// ResetLogging iterates through the known modules and sets the levels of all
// to UNSPECIFIED, except for <root> which is set to WARNING. The call also
// removes all writers in the DefaultContext and puts the original default
Expand Down
5 changes: 5 additions & 0 deletions global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@ func (*GlobalSuite) TestRemoveWriter(c *gc.C) {
c.Assert(err, gc.IsNil)
c.Assert(loggo.DefaultContext().WriterNames(), gc.HasLen, 0)
}

func (s *GlobalSuite) TestGetLoggerWithLabels(c *gc.C) {
logger := loggo.GetLoggerWithLabels("parent", "labela", "labelb")
c.Check(logger.Labels(), gc.DeepEquals, []string{"labela", "labelb"})
}
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ github.com/mattn/go-colorable v0.0.6 h1:jGqlOoCjqVR4hfTO9H1qrR2xi0xZNYmX2T1xlw7P
github.com/mattn/go-colorable v0.0.6/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c h1:3nKFouDdpgGUV/uerJcYWH45ZbJzX0SiVWfTgmUeTzc=
github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
gopkg.in/check.v1 v1.0.0-20160105164936-4f90aeace3a2 h1:+j1SppRob9bAgoYmsdW9NNBdKZfgYuWpqnYHv78Qt8w=
gopkg.in/check.v1 v1.0.0-20160105164936-4f90aeace3a2/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 comments on commit eebad3a

Please sign in to comment.