I’m writing a kubernetes controller that will have multiple log destinations: stdout/stderr, splunk and an external telemetry system. Note: I’m using logrus
Right now I’m tracking the loggers with a map:
// my config struct simplified
type Config struct {
Loggers *map[string]log.Logger
// other stuff
}
func NewConfig() *Config {
config := Config{}
// init stuff
return &config
}
Cfg := NewConfig()
// Setup default stderr logger
(*Cfg.Loggers)["default"] = *log.New()
// Configure my default logger
// Setup a splunk logger
// this will actually be however I integrate splunk, for now just another vanilla Logger
(*Cfg.Loggers)["splunk"] = *log.New()
// Sample log entry
(*Cfg.Loggers)["default"].Debugf("ERROR: %s", err)
Is this a sensible way of going about this? Is there a better way to do this?
I just have two concerns with this approach:
- The log statements are long and cumbersome, need some kind of alias mechanism to shorten log calls in my code. See the sample log entry above.
- I need a way to send a message to all log endpoints at once with a single statement, preferably using some built-in mechanism and not needing custom wrapper function(s)
Sorry, very new to go and not sure if I’m going about this the most idiomatic way.