@cryptotaxi247 / kubo / commits / bd51b8216

feat(eventlog) configuration/options

License: MIT Signed-off-by: Brian 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)

Brian Tiger Chow committed Nov 16, 2014 at 03:52 UTC bd51b8216075fc9639d54d6a18d6248e05b4f131
1 file changed +19 -6
util/elog/option.go
+19 -6
@@ -9,11 +9,14 @@ import (
9
10 type Option func()
11
12 -func SetOption(o Option) {
13 - o()
12 +func Configure(options ...Option) {
13 + for _, f := range options {
14 + f()
15 + }
16 }
17
16 -var JSONFormatter = func() {
18 +// LdJSONFormatter formats the event log as line-delimited JSON
19 +var LdJSONFormatter = func() {
20 logrus.SetFormatter(&logrus.JSONFormatter{})
21 }
22
@@ -22,7 +25,7 @@ var TextFormatter = func() {
25 }
26
27 type LogRotatorConfig struct {
25 - File string
28 + Filename string
29 MaxSizeMB uint64
30 MaxBackups uint64
31 MaxAgeDays uint64
@@ -39,7 +42,7 @@ func OutputRotatingLogFile(config LogRotatorConfig) Option {
42 return func() {
43 logrus.SetOutput(
44 &lumberjack.Logger{
42 - Filename: config.File,
45 + Filename: config.Filename,
46 MaxSize: int(config.MaxSizeMB),
47 MaxBackups: int(config.MaxBackups),
48 MaxAge: int(config.MaxAgeDays),
@@ -47,4 +50,14 @@ func OutputRotatingLogFile(config LogRotatorConfig) Option {
50 }
51 }
52
50 -// TODO log levels? logrus.SetLevel(logrus.DebugLevel)
53 +var LevelDebug = func() {
54 + logrus.SetLevel(logrus.DebugLevel)
55 +}
56 +
57 +var LevelError = func() {
58 + logrus.SetLevel(logrus.ErrorLevel)
59 +}
60 +
61 +var LevelInfo = func() {
62 + logrus.SetLevel(logrus.InfoLevel)
63 +}