Stern Stern Versions Save

⎈ Multi pod and container log tailing for Kubernetes -- Friendly fork of https://github.com/wercker/stern

v1.28.0

4 months ago

:zap: Notable Changes

Highlight matched strings in the log lines with the highlight option

Some part of a log line can be highlighted while still displaying all other logs lines.

--highlight flag now highlight matched strings in the log lines.

stern --highlight "\[error\]" .

v1.27.0

6 months ago

:zap: Notable Changes

Add new template function: toTimestamp

The toTimestamp function takes in an object, a layout, and optionally a timezone. This allows for more custom time parsing, for instance, if a user doesn't care about seeing the date of the log and only the time (in their own timezone) they can use a template such as:

--template '{{ with $msg := .Message | tryParseJSON }}[{{ toTimestamp $msg.time "15:04:05" "Local" }}] {{ $msg.msg }}{{ end }}{{ "\n" }}'

Add generic kubectl options

stern now has the generic options that kubectl has, and a new --show-hidden-options option.

$ stern --show-hidden-options
The following options can also be used in stern:
      --as string                      Username to impersonate for the operation. User could be a regular user or a service account in a namespace.
      --as-group stringArray           Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
      --as-uid string                  UID to impersonate for the operation.
      --cache-dir string               Default cache directory (default "/home/ksuda/.kube/cache")
      --certificate-authority string   Path to a cert file for the certificate authority
      --client-certificate string      Path to a client certificate file for TLS
      --client-key string              Path to a client key file for TLS
      --cluster string                 The name of the kubeconfig cluster to use
      --disable-compression            If true, opt-out of response compression for all requests to the server
      --insecure-skip-tls-verify       If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
      --request-timeout string         The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
      --server string                  The address and port of the Kubernetes API server
      --tls-server-name string         Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used
      --token string                   Bearer token for authentication to the API server
      --user string                    The name of the kubeconfig user to use

The number of kubectl generic options is so large that it makes it difficult to see stern's own list of options, so we usually hide them. Use --show-hidden-options if you want to list.

v1.26.0

8 months ago

:zap: Notable Changes

Add new template functions

The following template functions have been added in v1.26.0:

  • extractJSONParts: Parse string as JSON and concatenate the given keys
  • tryExtractJSONParts: Attempt to parse string as JSON and concatenate the given keys, returning text on failure

Changes

  • Fix the release workflow (#275) 91d4cd6 (Kazuki Suda)
  • Update dependencies and tools (#273) cb94677 (Takashi Kusumi)
  • Possibility to extract parts of a json-message. (#271) d49142c (Niels)
  • Fix potential panic in stern.Run() (#267) dcba2dd (Takashi Kusumi)
  • Add log level color keys and handle default (#264) 65204cc (Jimmie Högklint)
  • Fix typo in README.md (#261) d7d5a4f (Will May)
  • Integrate fmt and vet checks into golangci-lint (#260) 1d242bc (Takashi Kusumi)
  • Update Github Actions dependencies (#259) 9e833da (Takashi Kusumi)

v1.25.0

1 year ago

:zap: Notable Changes

Add support for the config file

You can now use the config file to change the default values of stern options. The default config file path is ~/.config/stern/config.yaml.

# <flag name>: <value>
tail: 10
max-log-requests: 999
timestamps: short

You can change the config file path with --config flag or STERNCONFIG environment variable.

Example

Changes

  • Fix the heading level in README.md (#257) c2290b4 (Kazuki Suda)
  • Update dependencies and tools (#256) 531f869 (Kazuki Suda)
  • Allow an empty config file (#255) c76ea87 (Takashi Kusumi)
  • Add support for the config file (#254) 2fdc298 (Kazuki Suda)
  • Make setup-go get Go version from go.mod (#253) 23feff7 (Takashi Kusumi)

v1.24.0

1 year ago

:zap: Nortable Changes

Add a short format for timestamps

--timestamps flag now accepts a format, one of default or short.

  • default: the original format 2006-01-02T15:04:05.000000000Z07:00 (RFC3339Nano with trailing zeros)
  • short: the new format 01-02 15:04:05 (time.DateTime without year).

If --timestamps is specified but without value, default is used to maintain backward compatibility.

$ stern --timestamps=short -n kube-system ds/kindnet --no-follow --tail 1 --only-log-lines
kindnet-hqn2k kindnet-cni 03-12 09:29:53 I0312 00:29:53.620499       1 main.go:250] Node kind-worker3 has CIDR [10.244.1.0/24]
kindnet-5f4ms kindnet-cni 03-12 09:29:53 I0312 00:29:53.374482       1 main.go:250] Node kind-worker3 has CIDR [10.244.1.0/24]

Add --node flag to filter on a specific node

New --node flag allows you to filter pods on a specific node. This flag will be helpful when we debug pods on the specific node.

# Print a DaemonSet pod on the specific node
stern --node <NODE_NAME> daemonsets/<DS_NAME>

# Print all pods on the specific node
stern --node <NODE_NAME> --all-namespaces --no-follow --max-log-requests 1 .

Highlight matched strings in the log lines with the include option

--include flag now highlight matched strings in the log lines.

image

Add all option to --container-state flag

--container-state flag now accepts all that is the same with specifying running,waiting,terminated. This change is helpful when we debug CrashLoopBackoff containers.

# Before
stern --container-state running,waiting,terminated <QUERY>

# After
stern --container-state all <QUERY>`

:warning: Breaking Changes

Add --max-log-requests flag to limit concurrent requests

New --max-log-requests flag allows you to limit concurrent requests to prevent unintentional load to a cluster. The behavior and the default are different depending on the presence of the --no-follow flag.

--no-follow default behavior
specified 5 limits the number of concurrent logs to request
not specified 50 exits with an error when if it reaches the concurrent limit

If you want to change to the same behavior as before, specify a sufficiently large value for --max-log-requests.

Change the default of --container-state flag to all

The default value of --container-state has been changed to all from running. With this change, stern will now show logs of completed (terminated) and CrashLoopBackoff (waiting) pods in addition to running pods by default.

If you want to change to the same behavior as before, explicitly specify --container-state to running.

Changes

  • Upgrade golang.org/x/net to fix a dependabot alert (#250) e26d049 (Kazuki Suda)
  • Add a short format for timestamps (#249) 43ab3f1 (Takashi Kusumi)
  • Bump golangci-lint to v1.51.2 (#248) 079d158 (Takashi Kusumi)
  • Add dynamic completion for --node flag (#244) 59d4453 (Takashi Kusumi)
  • Add --node flag to filter on a specific node (#243) f90f70f (Takashi Kusumi)
  • allow flexible log parsing and formatting (#239) 12a55fa (Dmytro Milinevskyi)
  • Documenting how to get Bash completion in Krew mode (#240) 24c8716 (Jesse Glick)
  • Add CI for skipped files (#241) 7131af2 (Takashi Kusumi)
  • Replace actions/cache with setup-go's cache (#238) 74952fd (Takashi Kusumi)
  • Make CI jobs faster (#237) 4bb340d (Kazuki Suda)
  • Refactor options.sternConfig() (#236) 2315b23 (Takashi Kusumi)
  • Return error when output option is invalid (#235) 1c5aa2b (Takashi Kusumi)
  • Refactor template logic (#233) 371daf1 (Takashi Kusumi)
  • Revert "add support to parse JSON logs (#228)" (#232) 202f7e8 (Dmytro Milinevskyi)
  • Change the default of --container-state to all (#225) 2502c91 (Takashi Kusumi)
  • Highlight matched strings in the log lines with the include option (#231) 9fbaa18 (Kazuki Suda)
  • Support resuming from the last log when retrying (#230) 52894f8 (Takashi Kusumi)
  • add support to parse JSON logs (#228) 72a5854 (Dmytro Milinevskyi)
  • Show initContainers first when --no-follow and --max-log-requests 1 (#226) ef753f1 (Takashi Kusumi)
  • Add --max-log-requests flag to limit concurrent requests (#224) 0b939c5 (Takashi Kusumi)
  • Improve handling of container termination (#221) 8312782 (Takashi Kusumi)
  • Allow pods without labels to be selected in the resource query (#223) fc51906 (Takashi Kusumi)
  • Add all option to --container-state flag (#222) 6e0d5fc (Takashi Kusumi)

v1.23.0

1 year ago

New features

Add --no-follow flag to exit when all logs have been shown

New --no-follow flag allows you to exit when all logs have been shown.

stern --no-follow .

Support <resource>/<name> form as a query

Stern now supports a Kubernetes resource query in the form <resource>/<name>. Pod query can still be used.

stern deployment/nginx

The following Kubernetes resources are supported:

  • daemonset
  • deployment
  • job
  • pod
  • replicaset
  • replicationcontroller
  • service
  • statefulset

Shell completion of stern already supports this feature.

Add --verbosity flag to set log level verbosity

New --verbosity flag allows you to set the log level verbosity of Kubernetes client-go. This feature is useful when you want to know how stern interacts with a Kubernetes API server in troubleshooting.

stern --verbosity=6 .

Add --only-log-lines flag to print only log lines

New --only-log-lines flag allows you to print only log lines (and errors if occur). The difference between not specifying the flag and specifying it is as follows:

$ stern . --tail=1 --no-follow
+ nginx-cfbcb7b98-96xsv › nginx
+ nginx-cfbcb7b98-29wn7 › nginx
nginx-cfbcb7b98-96xsv nginx 2023/01/27 13:20:48 [notice] 1#1: start worker process 46
- nginx-cfbcb7b98-96xsv › nginx
nginx-cfbcb7b98-29wn7 nginx 2023/01/27 13:20:45 [notice] 1#1: start worker process 46
- nginx-cfbcb7b98-29wn7 › nginx

$ stern . --tail=1 --no-follow --only-log-lines
nginx-cfbcb7b98-96xsv nginx 2023/01/27 13:20:48 [notice] 1#1: start worker process 46
nginx-cfbcb7b98-29wn7 nginx 2023/01/27 13:20:45 [notice] 1#1: start worker process 46

Changes

  • Allow to specify --exclude-pod/container multiple times (#218) b04478c (Kazuki Suda)
  • Add --only-log-lines flag that prints only log lines (#216) 995be39 (Kazuki Suda)
  • Fix typo of --verbosity flag (#215) 6c6db1d (Takashi Kusumi)
  • Add --verbosity flag to set log level verbosity (#214) 5327626 (Takashi Kusumi)
  • Add completion for flags with pre-defined choices (#211) e03646c (Takashi Kusumi)
  • Fix bug where container-state is ignored when no-follow specified (#210) 1bbee8c (Takashi Kusumi)
  • Add dynamic completion for a resource query (#209) 2983c8f (Takashi Kusumi)
  • Support <resource>/<name> form as a query (#208) 7bc45f0 (Takashi Kusumi)
  • Fix indent in update-readme.go (#207) daf2464 (Takashi Kusumi)
  • Update dependencies and tools (#205) 1bcb576 (Kazuki Suda)
  • Add --no-follow flag to exit when all logs have been shown (#204) a5e581d (Takashi Kusumi)
  • Use StringArrayVarP for --include and --exclude flags (#196) 80a68a9 (partcyborg)
  • Fix the invalid command in README.md (#193) f6e76ba (Kazuki Suda)

v1.22.0

1 year ago

News

You can now use the following two new output modes:

  • extjson is an extended json mode where the whole output is embeded in json and the namespace/pod/container values are color-coded as in the default mode.
  • ppextjson is the same as the above with pretty-print, so each field is on its own line.

Both of those modes can be piped into jq if you want full pretty-print, but you'll lose the original color-coding.

$ stern --output extjson .

$ stern --output extjson . | jq '.'

$ stern --output ppextjson .

See https://github.com/stern/stern/pull/190 for more details.

Changelog

  • Update dependencies (#192) f6f4f64 (Kazuki Suda)
  • Use Go 1.19 (#191) 0148388 (Kazuki Suda)
  • added output modes to colorize json output (#190) 3798ef5 (Prune Sebastien THOMAS)
  • Update dependencies (#183) 149cadf (Kazuki Suda)
  • Use Go 1.18 (#182) f403cf3 (Kazuki Suda)
  • Continue tailing logs even if timezone update fails (#178) 8fbf7d5 (Diego LAA)

v1.21.0

2 years ago

News

You can now use krew, the kubectl plugin manager, to install stern :tada:

kubectl krew install stern

stern has support for darwin/arm64 and windows/arm64 🥳

You can now parse JSON logs by using parseJSON function in --template flag. See https://github.com/stern/stern/pull/160 for more details.

stern --template='{{.PodName}}/{{.ContainerName}} {{with $d := .Message | parseJSON}}[{{$d.level}}] {{$d.message}}{{end}}{{"\n"}}' backend

Breaking changes

Since this version, the archive files will no longer be wrapped in a directory.

Before

$ tar -tf stern_1.20.1_darwin_amd64.tar.gz
stern_1.20.1_darwin_amd64/LICENSE
stern_1.20.1_darwin_amd64/stern

After

$ tar -tf stern_1.21.0_darwin_amd64.tar.gz
LICENSE
stern

Changelog

  • Disable uploading the krew plugin manifest using goreleaser (#175) cadf439 (Kazuki Suda)
  • Update Kubernetes vendors to v1.23.0 (#173) 4a9acc8 (Kazuki Suda)
  • Validate a krew plugin manifest file in the CI workflow (#171) 97c5837 (Kazuki Suda)
  • Allow to use stern as a kubectl plugin (#170) f98f149 (Kazuki Suda)
  • Use "go install" instead of "go get" (#169) 7e53a33 (Kazuki Suda)
  • Remove the pinned version of klog (#168) cad3668 (Kazuki Suda)
  • Add and export follow option to TailOptions (#162) 5240615 (Arthur Coelho)
  • Add a new function parseJSON to --template flag (#160) 60e2a77 (Kazuki Suda)

Docker images

  • docker pull ghcr.io/stern/stern:1
  • docker pull ghcr.io/stern/stern:1.21
  • docker pull ghcr.io/stern/stern:1.21.0

v1.20.1

2 years ago

Changelog

  • Use Go 1.17 (#157) a384d35 (Ryuichi KAWAMATA)
  • Fix a dependecy issue with klog (#154) bbcd61a (Kazuki Suda)

Docker images

  • docker pull ghcr.io/stern/stern:1
  • docker pull ghcr.io/stern/stern:1.20
  • docker pull ghcr.io/stern/stern:1.20.1

v1.20.0

2 years ago

Changelog

  • No longer need to set GO111MODULE=on due to default (#151) 0f9402d (Kazuki Suda)
  • Update vendors and tools (#150) ccc9b48 (Kazuki Suda)
  • Make watcher gets restarted in case of recoverable errors (#149) a363663 (Kazuki Suda)
  • Update Kubernetes vendors to v1.22.0 (#148) e74c88f (Kazuki Suda)
  • Fix "unexpected error: parsing time" error during parsing the logs (#147) 74b06c9 (Kazuki Suda)
  • Add @rkmathi to CODEOWNERS 6324fc2 (Kazuki Suda)
  • Add missing closing parenthesis (#144) c723f0d (Farzad Majidfayyaz)
  • Support dynamic completion for fish shell ee0463d (Kazuki Suda)
  • Add a dynamic completion for --context fed5c4d (Kazuki Suda)
  • Add a dynamic completion for --namespace 83ba922 (Kazuki Suda)
  • Use new dynamic completion 736575e (Kazuki Suda)

Docker images

  • docker pull ghcr.io/stern/stern:1
  • docker pull ghcr.io/stern/stern:1.20
  • docker pull ghcr.io/stern/stern:1.20.0