add tag name
This commit is contained in:
parent
39bf8b8356
commit
7fbf9095f5
@ -3,6 +3,7 @@ package gelfexporter
|
||||
type config struct {
|
||||
GelfUrl string
|
||||
AppName string
|
||||
Tag string
|
||||
}
|
||||
|
||||
// newConfig creates a validated Config configured with options.
|
||||
@ -40,3 +41,14 @@ func (o appName) apply(cfg config) config {
|
||||
cfg.AppName = string(o)
|
||||
return cfg
|
||||
}
|
||||
|
||||
func WithTag(tagStr string) Option {
|
||||
return tag(tagStr)
|
||||
}
|
||||
|
||||
type tag string
|
||||
|
||||
func (o tag) apply(cfg config) config {
|
||||
cfg.Tag = string(o)
|
||||
return cfg
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ type GELFMessage struct {
|
||||
|
||||
// All additional field names must start with an underline.
|
||||
ExtraFields map[string]interface{} `json:"extrafields,omitempty"`
|
||||
|
||||
Tag string `json:"tag,omitempty"`
|
||||
}
|
||||
|
||||
func Log(writer *gelf.UDPWriter, msg GELFMessage) {
|
||||
@ -38,6 +40,7 @@ func Log(writer *gelf.UDPWriter, msg GELFMessage) {
|
||||
|
||||
func (g GELFMessage) GELFFormat() *gelf.Message {
|
||||
prefixedExtras := make(map[string]interface{}, len(g.ExtraFields))
|
||||
prefixedExtras["tag"] = g.Tag
|
||||
for k, v := range g.ExtraFields {
|
||||
prefixedExtras["_"+k] = v
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ func New(options ...Option) (*Exporter, error) {
|
||||
return &Exporter{
|
||||
gelfWriter: writer,
|
||||
appName: cfg.AppName,
|
||||
tag: cfg.Tag,
|
||||
}, nil
|
||||
|
||||
}
|
||||
@ -37,6 +38,7 @@ func New(options ...Option) (*Exporter, error) {
|
||||
type Exporter struct {
|
||||
gelfWriter *gelf.UDPWriter
|
||||
appName string
|
||||
tag string
|
||||
stoppedMu sync.RWMutex
|
||||
stopped bool
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user