提交 bd51b821 作者: Brian Tiger Chow

feat(eventlog) configuration/options

License: MIT
Signed-off-by: 's avatarBrian Tiger Chow <brian@perfmode.com>

# TYPES
# feat
# fix
# docs
# style (formatting, missing semi colons, etc; no code change):
# refactor
# test (adding missing tests, refactoring tests; no production code change)
# chore (updating grunt tasks etc; no production code change)
上级 d28c9cc7
...@@ -9,11 +9,14 @@ import ( ...@@ -9,11 +9,14 @@ import (
type Option func() type Option func()
func SetOption(o Option) { func Configure(options ...Option) {
o() for _, f := range options {
f()
}
} }
var JSONFormatter = func() { // LdJSONFormatter formats the event log as line-delimited JSON
var LdJSONFormatter = func() {
logrus.SetFormatter(&logrus.JSONFormatter{}) logrus.SetFormatter(&logrus.JSONFormatter{})
} }
...@@ -22,7 +25,7 @@ var TextFormatter = func() { ...@@ -22,7 +25,7 @@ var TextFormatter = func() {
} }
type LogRotatorConfig struct { type LogRotatorConfig struct {
File string Filename string
MaxSizeMB uint64 MaxSizeMB uint64
MaxBackups uint64 MaxBackups uint64
MaxAgeDays uint64 MaxAgeDays uint64
...@@ -39,7 +42,7 @@ func OutputRotatingLogFile(config LogRotatorConfig) Option { ...@@ -39,7 +42,7 @@ func OutputRotatingLogFile(config LogRotatorConfig) Option {
return func() { return func() {
logrus.SetOutput( logrus.SetOutput(
&lumberjack.Logger{ &lumberjack.Logger{
Filename: config.File, Filename: config.Filename,
MaxSize: int(config.MaxSizeMB), MaxSize: int(config.MaxSizeMB),
MaxBackups: int(config.MaxBackups), MaxBackups: int(config.MaxBackups),
MaxAge: int(config.MaxAgeDays), MaxAge: int(config.MaxAgeDays),
...@@ -47,4 +50,14 @@ func OutputRotatingLogFile(config LogRotatorConfig) Option { ...@@ -47,4 +50,14 @@ func OutputRotatingLogFile(config LogRotatorConfig) Option {
} }
} }
// TODO log levels? logrus.SetLevel(logrus.DebugLevel) var LevelDebug = func() {
logrus.SetLevel(logrus.DebugLevel)
}
var LevelError = func() {
logrus.SetLevel(logrus.ErrorLevel)
}
var LevelInfo = func() {
logrus.SetLevel(logrus.InfoLevel)
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论