Skip to content

Commit 202f7e8

Browse files
authored
Revert "add support to parse JSON logs (#228)" (#232)
This reverts commit 72a5854.
1 parent 2502c91 commit 202f7e8

File tree

2 files changed

+3
-48
lines changed

2 files changed

+3
-48
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ Supported Kubernetes resources are `pod`, `replicationcontroller`, `service`, `d
8282
`--exclude-container`, `-E` | `[]` | Container name to exclude when multiple containers in pod. (regular expression)
8383
`--exclude-pod` | `[]` | Pod name to exclude. (regular expression)
8484
`--field-selector` | | Selector (field query) to filter on. If present, default to ".*" for the pod-query.
85-
`--formatter`, `-F` | `default` | Specify formatter template (transformation from a specific log format to human-friendly output). Currently support: [default, zap-json]
8685
`--include`, `-i` | `[]` | Log lines to include. (regular expression)
8786
`--init-containers` | `true` | Include or exclude init containers.
8887
`--kubeconfig` | | Path to kubeconfig file to use. Default to KUBECONFIG variable then ~/.kube/config path.

cmd/cmd.go

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ type options struct {
6363
completion string
6464
template string
6565
output string
66-
formatter string
6766
prompt bool
6867
podQuery string
6968
noFollow bool
@@ -83,7 +82,6 @@ func NewOptions(streams genericclioptions.IOStreams) *options {
8382
initContainers: true,
8483
ephemeralContainers: true,
8584
output: "default",
86-
formatter: "default",
8785
since: 48 * time.Hour,
8886
tail: -1,
8987
template: "",
@@ -236,36 +234,24 @@ func (o *options) sternConfig() (*stern.Config, error) {
236234
return nil, errors.New("color should be one of 'always', 'never', or 'auto'")
237235
}
238236

239-
messageTpl := "{{.Message}}"
240-
switch o.formatter {
241-
case "zap-json":
242-
if color.NoColor {
243-
messageTpl = `{{ with $msg := .Message | parseJSON }}[{{ $msg.ts }}] {{ $msg.level }} ({{ $msg.caller }}) {{ $msg.msg }}{{ end }}`
244-
} else {
245-
messageTpl = `{{ with $msg := .Message | parseJSON }}[{{ colorGreen $msg.ts }}] {{ levelColor $msg.level }} ({{ colorCyan $msg.caller }}) {{ $msg.msg }}{{ end }}`
246-
}
247-
case "default":
248-
default:
249-
return nil, errors.New("input format should be one of 'default', 'zap-json'")
250-
}
251237
t := o.template
252238
if t == "" {
253239
switch o.output {
254240
case "default":
255241
if color.NoColor {
256-
t = "{{.PodName}} {{.ContainerName}} " + messageTpl
242+
t = "{{.PodName}} {{.ContainerName}} {{.Message}}"
257243
if o.allNamespaces || len(o.namespaces) > 1 {
258244
t = fmt.Sprintf("{{.Namespace}} %s", t)
259245
}
260246
} else {
261-
t = "{{color .PodColor .PodName}} {{color .ContainerColor .ContainerName}} " + messageTpl
247+
t = "{{color .PodColor .PodName}} {{color .ContainerColor .ContainerName}} {{.Message}}"
262248
if o.allNamespaces || len(o.namespaces) > 1 {
263249
t = fmt.Sprintf("{{color .PodColor .Namespace}} %s", t)
264250
}
265251

266252
}
267253
case "raw":
268-
t = messageTpl
254+
t = "{{.Message}}"
269255
case "json":
270256
t = "{{json .}}"
271257
case "extjson":
@@ -312,35 +298,6 @@ func (o *options) sternConfig() (*stern.Config, error) {
312298
"color": func(color color.Color, text string) string {
313299
return color.SprintFunc()(text)
314300
},
315-
"colorBlack": color.BlackString,
316-
"colorRed": color.RedString,
317-
"colorGreen": color.GreenString,
318-
"colorYellow": color.YellowString,
319-
"colorBlue": color.BlueString,
320-
"colorMagenta": color.MagentaString,
321-
"colorCyan": color.CyanString,
322-
"colorWhite": color.WhiteString,
323-
"levelColor": func(level string) string {
324-
var levelColor *color.Color
325-
switch strings.ToLower(level) {
326-
case "debug":
327-
levelColor = color.New(color.FgMagenta)
328-
case "info":
329-
levelColor = color.New(color.FgBlue)
330-
case "warn":
331-
levelColor = color.New(color.FgYellow)
332-
case "error":
333-
levelColor = color.New(color.FgRed)
334-
case "dpanic":
335-
levelColor = color.New(color.FgRed)
336-
case "panic":
337-
levelColor = color.New(color.FgRed)
338-
case "fatal":
339-
levelColor = color.New(color.FgCyan)
340-
default:
341-
}
342-
return levelColor.SprintFunc()(level)
343-
},
344301
}
345302
template, err := template.New("log").Funcs(funs).Parse(t)
346303
if err != nil {
@@ -432,7 +389,6 @@ func (o *options) AddFlags(fs *pflag.FlagSet) {
432389
fs.StringSliceVarP(&o.namespaces, "namespace", "n", o.namespaces, "Kubernetes namespace to use. Default to namespace configured in kubernetes context. To specify multiple namespaces, repeat this or set comma-separated value.")
433390
fs.IntVar(&o.maxLogRequests, "max-log-requests", o.maxLogRequests, "Maximum number of concurrent logs to request. Defaults to 50, but 5 when specifying --no-follow")
434391
fs.StringVarP(&o.output, "output", "o", o.output, "Specify predefined template. Currently support: [default, raw, json, extjson, ppextjson]")
435-
fs.StringVarP(&o.formatter, "formatter", "F", o.formatter, "Specify formatter template (transformation from a specific log format to human-friendly output). Currently support: [default, zap-json]")
436392
fs.BoolVarP(&o.prompt, "prompt", "p", o.prompt, "Toggle interactive prompt for selecting 'app.kubernetes.io/instance' label values.")
437393
fs.StringVarP(&o.selector, "selector", "l", o.selector, "Selector (label query) to filter on. If present, default to \".*\" for the pod-query.")
438394
fs.StringVar(&o.fieldSelector, "field-selector", o.fieldSelector, "Selector (field query) to filter on. If present, default to \".*\" for the pod-query.")

0 commit comments

Comments
 (0)