Skip to content

Commit 0974323

Browse files
ShohamBitjosedonizetti
authored andcommitted
flags(log)!: new flag format
BREAKING CHANGE: add --logging to replace --log
1 parent 1fa65a8 commit 0974323

File tree

25 files changed

+1379
-992
lines changed

25 files changed

+1379
-992
lines changed

cmd/tracee/cmd/analyze.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ func init() {
4949
)
5050

5151
analyzeCmd.Flags().StringArrayP(
52-
"log",
53-
"l",
54-
[]string{"info"},
55-
"Logger options [debug|info|warn...]",
52+
flags.LoggingFlag,
53+
flags.LoggingFlagShort,
54+
[]string{flags.DefaultLogLevelFlag},
55+
"Logger options",
5656
)
5757
}
5858

@@ -71,21 +71,21 @@ tracee analyze --events anti_debugging --source events.json`,
7171
bindViperFlag(cmd, "events")
7272
bindViperFlag(cmd, "source")
7373
bindViperFlag(cmd, "output")
74-
bindViperFlag(cmd, "log")
74+
bindViperFlag(cmd, flags.LoggingFlag)
7575
bindViperFlag(cmd, "signatures-dir")
7676
},
7777
Run: command,
7878
DisableFlagsInUseLine: true,
7979
}
8080

8181
func command(cmd *cobra.Command, args []string) {
82-
logFlags := viper.GetStringSlice("log")
82+
logFlags := viper.GetStringSlice(flags.LoggingFlag)
8383

84-
logCfg, err := flags.PrepareLogger(logFlags)
84+
loggerConfig, err := flags.PrepareLogger(logFlags)
8585
if err != nil {
8686
logger.Fatalw("Failed to prepare logger", "error", err)
8787
}
88-
logger.Init(logCfg)
88+
logger.Init(loggerConfig.GetLoggingConfig())
8989

9090
// Set up input
9191
sourcePath := viper.GetString("source")

cmd/tracee/cmd/man.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func init() {
5656
configCmd,
5757
containersCmd,
5858
eventsCmd,
59-
logCmd,
59+
loggingCmd,
6060
outputCmd,
6161
scopeCmd,
6262
serverCmd,
@@ -132,12 +132,12 @@ var eventsCmd = &cobra.Command{
132132
},
133133
}
134134

135-
var logCmd = &cobra.Command{
136-
Use: "log",
135+
var loggingCmd = &cobra.Command{
136+
Use: "logging",
137137
Aliases: []string{"l"},
138-
Short: "Show manual page for the --log flag",
138+
Short: "Show manual page for the --logging flag",
139139
RunE: func(cmd *cobra.Command, args []string) error {
140-
return runManForFlag("log")
140+
return runManForFlag("logging")
141141
},
142142
}
143143

cmd/tracee/cmd/root.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,12 @@ func initCmd() error {
279279
}
280280

281281
rootCmd.Flags().StringArrayP(
282-
"log",
283-
"l",
284-
[]string{"info"},
282+
flags.LoggingFlag,
283+
flags.LoggingFlagShort,
284+
[]string{flags.DefaultLogLevelFlag},
285285
"[debug|info|warn...]\t\tLogger options",
286286
)
287-
err = viper.BindPFlag("log", rootCmd.Flags().Lookup("log"))
287+
err = viper.BindPFlag(flags.LoggingFlag, rootCmd.Flags().Lookup(flags.LoggingFlag))
288288
if err != nil {
289289
return errfmt.WrapError(err)
290290
}

deploy/helm/tracee/templates/tracee-config.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,91 @@ data:
2525
{{- end }}
2626
log:
2727
level: {{ .Values.config.log.level }}
28+
{{- if .Values.config.log.file }}
29+
file: {{ .Values.config.log.file }}
30+
{{- end }}
31+
{{- if .Values.config.log.aggregate }}
32+
aggregate:
33+
enabled: {{ .Values.config.log.aggregate.enabled | default false }}
34+
{{- if .Values.config.log.aggregate.flushInterval }}
35+
flush-interval: {{ .Values.config.log.aggregate.flushInterval }}
36+
{{- end }}
37+
{{- end }}
38+
{{- if .Values.config.log.filters }}
39+
filters:
40+
{{- if .Values.config.log.filters.libbpf }}
41+
libbpf: {{ .Values.config.log.filters.libbpf }}
42+
{{- end }}
43+
{{- if .Values.config.log.filters.include }}
44+
include:
45+
{{- if .Values.config.log.filters.include.msg }}
46+
msg:
47+
{{- range .Values.config.log.filters.include.msg }}
48+
- {{ . }}
49+
{{- end }}
50+
{{- end }}
51+
{{- if .Values.config.log.filters.include.pkg }}
52+
pkg:
53+
{{- range .Values.config.log.filters.include.pkg }}
54+
- {{ . }}
55+
{{- end }}
56+
{{- end }}
57+
{{- if .Values.config.log.filters.include.file }}
58+
file:
59+
{{- range .Values.config.log.filters.include.file }}
60+
- {{ . }}
61+
{{- end }}
62+
{{- end }}
63+
{{- if .Values.config.log.filters.include.level }}
64+
level:
65+
{{- range .Values.config.log.filters.include.level }}
66+
- {{ . }}
67+
{{- end }}
68+
{{- end }}
69+
{{- if .Values.config.log.filters.include.regex }}
70+
regex:
71+
{{- range .Values.config.log.filters.include.regex }}
72+
- {{ . }}
73+
{{- end }}
74+
{{- end }}
75+
{{- if .Values.config.log.filters.include.libbpf }}
76+
libbpf: {{ .Values.config.log.filters.include.libbpf }}
77+
{{- end }}
78+
{{- end }}
79+
{{- if .Values.config.log.filters.exclude }}
80+
exclude:
81+
{{- if .Values.config.log.filters.exclude.msg }}
82+
msg:
83+
{{- range .Values.config.log.filters.exclude.msg }}
84+
- {{ . }}
85+
{{- end }}
86+
{{- end }}
87+
{{- if .Values.config.log.filters.exclude.pkg }}
88+
pkg:
89+
{{- range .Values.config.log.filters.exclude.pkg }}
90+
- {{ . }}
91+
{{- end }}
92+
{{- end }}
93+
{{- if .Values.config.log.filters.exclude.file }}
94+
file:
95+
{{- range .Values.config.log.filters.exclude.file }}
96+
- {{ . }}
97+
{{- end }}
98+
{{- end }}
99+
{{- if .Values.config.log.filters.exclude.level }}
100+
level:
101+
{{- range .Values.config.log.filters.exclude.level }}
102+
- {{ . }}
103+
{{- end }}
104+
{{- end }}
105+
{{- if .Values.config.log.filters.exclude.regex }}
106+
regex:
107+
{{- range .Values.config.log.filters.exclude.regex }}
108+
- {{ . }}
109+
{{- end }}
110+
{{- end }}
111+
{{- end }}
112+
{{- end }}
28113
output:
29114
{{ .Values.config.output.format }}:
30115
files:

deploy/helm/tracee/values.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,39 @@ config:
9090
signaturesDir: ""
9191
log:
9292
level: info
93+
# file: "/var/log/tracee.log"
94+
# aggregate:
95+
# enabled: true
96+
# flush-interval: "5s"
97+
# filters:
98+
# include:
99+
# libbpf: false
100+
# msg:
101+
# - SampleMessage1
102+
# - SampleMessage2
103+
# pkg:
104+
# - package1
105+
# - package2
106+
# file:
107+
# - file1.go
108+
# - file2.go
109+
# level:
110+
# - warn
111+
# - error
112+
# regex:
113+
# - ^pattern1
114+
# - ^pattern2
115+
# exclude:
116+
# msg:
117+
# - ExcludedMessage1
118+
# pkg:
119+
# - excludedPackage
120+
# file:
121+
# - excludedFile.go
122+
# level:
123+
# - debug
124+
# regex:
125+
# - ^excludedPattern
93126
output:
94127
format: json
95128
options:

docs/docs/flags/log.1.md

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)