Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (

// LogglyHook to send logs to the Loggly service.
type LogglyHook struct {
client *loggly.Client
host string
levels []logrus.Level
client *loggly.Client
host string
levels []logrus.Level
ignoreHostField bool
}

const (
Expand Down Expand Up @@ -78,10 +79,13 @@ func (hook *LogglyHook) Fire(entry *logrus.Entry) error {
"timestamp": entry.Time.UTC().Format(RFC3339Micro),
"level": strings.ToUpper(level),
"message": entry.Message,
"host": hook.host,
"data": data,
}

if !hook.ignoreHostField {
logglyMessage["host"] = hook.host
}

err := hook.client.Send(logglyMessage)
if err != nil {
log := logrus.New()
Expand All @@ -108,3 +112,8 @@ func (hook *LogglyHook) Flush() {
func (hook *LogglyHook) Levels() []logrus.Level {
return hook.levels
}

// IgnoreHostField sets if ignore pushing host field
func (hook *LogglyHook) IgnoreHostField(ignore bool) {
hook.ignoreHostField = ignore
}