Skip to content

Commit 03a5022

Browse files
justonedev1teo
authored andcommitted
added logging filters for IL
1 parent ba1f643 commit 03a5022

5 files changed

Lines changed: 46 additions & 25 deletions

File tree

cmd/o2-aliecs-core/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,18 @@ func init() {
8787
ForceFormatting: true,
8888
})
8989
log.SetOutput(os.Stdout)
90-
ilHook, err := infologger.NewDirectHook("ECS", "core")
91-
if err == nil {
92-
log.AddHook(ilHook)
93-
}
9490
}
9591

9692
func main() {
9793
if err := core.NewConfig(); err != nil {
9894
log.Fatal(err)
9995
}
10096

97+
ilHook, err := infologger.NewDirectHook("ECS", "core", nil)
98+
if err == nil {
99+
log.AddHook(ilHook)
100+
}
101+
101102
if err := core.Run(); err != nil {
102103
log.Fatal(err)
103104
}

cmd/o2-aliecs-executor/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737

3838
func init() {
3939
logrus.SetOutput(os.Stdout)
40-
ilHook, err := infologger.NewDirectHook("ECS", "executor")
40+
ilHook, err := infologger.NewDirectHook("ECS", "executor", logrus.AllLevels)
4141
if err == nil {
4242
logrus.AddHook(ilHook)
4343
}

cmd/o2-apricot/main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,27 @@ import (
3535

3636
func init() {
3737
log.SetFormatter(&prefixed.TextFormatter{
38-
FullTimestamp: true,
39-
SpacePadding: 20,
40-
PrefixPadding: 12,
38+
FullTimestamp: true,
39+
SpacePadding: 20,
40+
PrefixPadding: 12,
4141

4242
// Needed for colored stdout/stderr in GoLand, IntelliJ, etc.
4343
ForceColors: true,
4444
ForceFormatting: true,
4545
})
4646
log.SetOutput(os.Stdout)
47-
ilHook, err := infologger.NewDirectHook("ECS", "apricot")
48-
if err == nil {
49-
log.AddHook(ilHook)
50-
}
5147
}
5248

5349
func main() {
5450
if err := apricot.NewConfig(); err != nil {
5551
log.Fatal(err)
5652
}
5753

54+
ilHook, err := infologger.NewDirectHook("ECS", "apricot", nil)
55+
if err == nil {
56+
log.AddHook(ilHook)
57+
}
58+
5859
if err := apricot.Run(); err != nil {
5960
log.Fatal(err)
6061
}

common/logger/infologger/directhook.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838

3939
"github.com/AliceO2Group/Control/common/utils"
4040
"github.com/sirupsen/logrus"
41+
"github.com/spf13/viper"
4142
)
4243

4344
const INFOLOGGER_MAX_MESSAGE_SIZE = 1024
@@ -46,8 +47,26 @@ var (
4647
hostname string
4748
Pid string
4849
username string
50+
51+
logILInfoLevel = []logrus.Level{
52+
logrus.PanicLevel,
53+
logrus.FatalLevel,
54+
logrus.ErrorLevel,
55+
logrus.WarnLevel,
56+
logrus.InfoLevel,
57+
}
58+
logILAllLevel = logrus.AllLevels
59+
currentIlLevel = logILInfoLevel
4960
)
5061

62+
func setCurrentILLevelFromViper() {
63+
if viper.GetBool("logAllIL") {
64+
currentIlLevel = logILAllLevel
65+
} else {
66+
currentIlLevel = logILInfoLevel
67+
}
68+
}
69+
5170
var lineBreaksRe = regexp.MustCompile(`\r?\n`)
5271

5372
func init() {
@@ -140,7 +159,14 @@ func guessSocketPath() string {
140159
}
141160
}
142161

143-
func NewDirectHook(defaultSystem string, defaultFacility string) (*DirectHook, error) {
162+
func NewDirectHook(defaultSystem string, defaultFacility string, levelsToLog []logrus.Level) (*DirectHook, error) {
163+
164+
if levelsToLog == nil {
165+
setCurrentILLevelFromViper()
166+
} else {
167+
currentIlLevel = levelsToLog
168+
}
169+
144170
socketPath := guessSocketPath()
145171
sender := newSender(socketPath)
146172
if sender == nil {
@@ -154,25 +180,16 @@ func NewDirectHook(defaultSystem string, defaultFacility string) (*DirectHook, e
154180
}, nil
155181
}
156182

157-
func NewDirectHookWithRole(defaultSystem string, defaultFacility string, defaultRole string) (*DirectHook, error) {
158-
dh, err := NewDirectHook(defaultSystem, defaultFacility)
183+
func NewDirectHookWithRole(defaultSystem string, defaultFacility string, defaultRole string, levelsToLog []logrus.Level) (*DirectHook, error) {
184+
dh, err := NewDirectHook(defaultSystem, defaultFacility, levelsToLog)
159185
if dh != nil {
160186
dh.role = defaultRole
161187
}
162188
return dh, err
163189
}
164190

165191
func (h *DirectHook) Levels() []logrus.Level {
166-
// Everything except Trace
167-
return []logrus.Level{
168-
logrus.PanicLevel,
169-
logrus.FatalLevel,
170-
logrus.ErrorLevel,
171-
logrus.WarnLevel,
172-
logrus.InfoLevel,
173-
logrus.DebugLevel,
174-
logrus.TraceLevel,
175-
}
192+
return currentIlLevel
176193
}
177194

178195
func (h *DirectHook) Fire(e *logrus.Entry) error {

core/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func setDefaults() error {
124124
viper.SetDefault("taskClassCacheTTL", 7*24*time.Hour)
125125
viper.SetDefault("kafkaEndpoints", []string{"localhost:9092"})
126126
viper.SetDefault("enableKafka", true)
127+
viper.SetDefault("logAllIL", false)
127128
return nil
128129
}
129130

@@ -190,6 +191,7 @@ func setFlags() error {
190191
pflag.Duration("taskClassCacheTTL", viper.GetDuration("taskClassCacheTTL"), "TTL for task class cache entries")
191192
pflag.StringSlice("kafkaEndpoints", viper.GetStringSlice("kafkaEndpoints"), "List of Kafka endpoints to connect to (default: localhost:9092)")
192193
pflag.Bool("enableKafka", viper.GetBool("enableKafka"), "Turn on the kafka messaging")
194+
pflag.Bool("logAllIL", viper.GetBool("logAllIL"), "Send all the logs into IL, including Debug and Trace messages")
193195

194196
pflag.Parse()
195197
return viper.BindPFlags(pflag.CommandLine)

0 commit comments

Comments
 (0)