github.com/GoogleContainerTools/skaffold/v2@v2.13.2/docs-v2/content/en/docs/log-tailing.md (about) 1 --- 2 title: "Log Tailing" 3 linkTitle: "Log Tailing" 4 weight: 44 5 featureId: logging 6 aliases: [docs/pipeline-stages/log-tailing] 7 --- 8 9 Skaffold has built-in support for tailing logs for containers **built and deployed by Skaffold** on your cluster 10 to your local machine when running in either `dev`, `debug` or `run` mode. 11 12 {{< alert title="Note" >}} 13 Log Tailing is **enabled by default** for [`dev`]({{<relref "/docs/workflows/dev" >}}) and [`debug`]({{<relref "/docs/workflows/debug" >}}).<br> 14 Log Tailing is **disabled by default** for `run` mode; it can be enabled with the `--tail` flag. 15 {{< /alert >}} 16 17 18 ## Log Structure 19 To view log structure, run `skaffold run --tail` in [`examples/microservices`](https://github.com/GoogleContainerTools/skaffold/tree/main/examples/microservices) 20 21 ```bash 22 skaffold run --tail 23 ``` 24 25 will produce an output like this 26 27  28 29 30 For every log line, skaffold will prefix the pod name and container name if they're not the same. 31 32  33 34 In the above example, `leeroy-web-75ff54dc77-9shwm` is the pod name and `leeroy-web` is container name 35 defined in the spec for this deployment 36 37 ```yaml 38 apiVersion: apps/v1 39 kind: Deployment 40 metadata: 41 name: leeroy-web 42 labels: 43 app: leeroy-web 44 spec: 45 replicas: 1 46 selector: 47 matchLabels: 48 app: leeroy-web 49 template: 50 metadata: 51 labels: 52 app: leeroy-web 53 spec: 54 containers: 55 - name: leeroy-web 56 image: gcr.io/k8s-skaffold/leeroy-web 57 ports: 58 - containerPort: 8080 59 ``` 60 61 Skaffold will choose a unique color for each container to make it easy for users to read the logs. 62 63 ## JSON Parsing 64 In some cases, logs may simply be JSON objects. 65 If you know this ahead of time and know that you'd like to only get specific fields from these objects, 66 you can add a `deploy.logs.jsonParse` stanza to your `skaffold.yaml` file to configure which fields you'd like to see. 67 68 ```yaml 69 apiVersion: skaffold/v2beta27 70 kind: Config 71 build: 72 artifacts: 73 - image: skaffold-example 74 deploy: 75 logs: 76 jsonParse: 77 fields: ["message", "severity"] 78 kubectl: 79 manifests: 80 - k8s-* 81 ``` 82 In the above example, only the fields `message` and `severity` will be gathered from the incoming JSON logs. 83 So, if the logs coming through were structured like so: 84 ``` 85 [getting-started] {"timestampSeconds":1643740871,"timestampNanos":446000000,"severity":"INFO","thread":"main","message":"Hello World!","context":"default"} 86 ``` 87 with the `deploy.logs.jsonParse` config added, they would look like this: 88 ``` 89 [getting-started] message: Hello World!, severity: INFO 90 ```