-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
36 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package logri | ||
|
||
import "github.com/Sirupsen/logrus" | ||
|
||
// LoggerHook is a Logrus hook that adds the logger name as a field to the entry | ||
type LoggerHook struct { | ||
loggerName string | ||
} | ||
|
||
// Levels satisfies the logrus.Hook interface | ||
func (hook LoggerHook) Levels() []logrus.Level { | ||
return logrus.AllLevels | ||
} | ||
|
||
// Fire satisfies the logrus.Hook interface | ||
func (hook LoggerHook) Fire(entry *logrus.Entry) error { | ||
entry.Data["logger"] = hook.loggerName | ||
return nil | ||
} | ||
|
||
func copyHooksExceptLoggerHook(orig logrus.LevelHooks) logrus.LevelHooks { | ||
result := logrus.LevelHooks{} | ||
for level, hooks := range orig { | ||
for _, hook := range hooks { | ||
if _, ok := hook.(LoggerHook); !ok { | ||
result[level] = append(result[level], hook) | ||
} | ||
} | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters