Commit bd51b821 authored by Brian Tiger Chow's avatar Brian Tiger Chow

feat(eventlog) configuration/options

License: MIT
Signed-off-by: default 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)
parent 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 is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment