Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
38
models/common.go
Normal file
38
models/common.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
)
|
||||
|
||||
// logName returns the log-friendly name/type.
|
||||
func logName(pluginType, name, alias string) string {
|
||||
if alias == "" {
|
||||
return pluginType + "." + name
|
||||
}
|
||||
return pluginType + "." + name + "::" + alias
|
||||
}
|
||||
|
||||
func SetLoggerOnPlugin(i interface{}, logger telegraf.Logger) {
|
||||
valI := reflect.ValueOf(i)
|
||||
|
||||
if valI.Type().Kind() != reflect.Ptr {
|
||||
valI = reflect.New(reflect.TypeOf(i))
|
||||
}
|
||||
|
||||
field := valI.Elem().FieldByName("Log")
|
||||
if !field.IsValid() {
|
||||
return
|
||||
}
|
||||
|
||||
switch field.Type().String() {
|
||||
case "telegraf.Logger":
|
||||
if field.CanSet() {
|
||||
field.Set(reflect.ValueOf(logger))
|
||||
}
|
||||
default:
|
||||
logger.Debugf("Plugin %q defines a 'Log' field on its struct of an unexpected type %q. Expected telegraf.Logger",
|
||||
valI.Type().Name(), field.Type().String())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue