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