检查linux服务日志时是否可以自动换行日志输出

检查linux服务日志时是否可以自动换行日志输出

当我使用此命令检查linux服务日志时:

root@k8sslave01:/usr/lib/systemd/system# systemctl status kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
     Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; preset: enabled)
    Drop-In: /usr/lib/systemd/system/kubelet.service.d
             └─10-kubeadm.conf
     Active: active (running) since Sat 2023-11-11 20:57:40 CST; 38min ago
       Docs: https://kubernetes.io/docs/
   Main PID: 22401 (kubelet)
      Tasks: 10 (limit: 2025)
     Memory: 48.5M
        CPU: 21.417s
     CGroup: /system.slice/kubelet.service
             └─22401 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --container-runtime-endpoint=unix:///var/run/containerd/contai>

Nov 11 21:35:42 k8sslave01 kubelet[22401]: E1111 21:35:42.042501   22401 kuberuntime_sandbox.go:72] "Failed to create sandbox for pod" err="rpc error: code = Unknown desc = failed to get sandbox image \"registry.k8s.io/pause:3.6\": failed to >
Nov 11 21:35:42 k8sslave01 kubelet[22401]: E1111 21:35:42.042521   22401 kuberuntime_manager.go:1166] "CreatePodSandbox for pod failed" err="rpc error: code = Unknown desc = failed to get sandbox image \"registry.k8s.io/pause:3.6\": failed to>
Nov 11 21:35:42 k8sslave01 kubelet[22401]: E1111 21:35:42.042593   22401 pod_workers.go:1300] "Error syncing pod, skipping" err="failed to \"CreatePodSandbox\" for \"calico-node-lsxn7_calico-system(a53e96ad-d80b-4589-8ce5-7b76f4f3dc0d)\" with>
Nov 11 21:35:44 k8sslave01 kubelet[22401]: E1111 21:35:44.006706   22401 pod_workers.go:1300] "Error syncing pod, skipping" err="network is not ready: container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady messag>

我只看到部分日志输出,是否可以在linux终端中自动包装日志输出?这是用户界面输出:

在此输入图像描述

黑色箭头内容无法在终端中显示。如何自动换行输出内容?

答案1

如果您不介意丢失颜色,则可以通过管道传输到cat哪个应该导致终端包装输出。比较:

  • systemctl status thermald.service

    展开的 systemctl status Thermald.service 输出的屏幕截图

  • systemctl status thermald.service | cat

    包装后的 systemctl status Thermald.service 的屏幕截图 |猫输出

更简单的是,使用-l--no-pager

systemctl status 的输出 --no-pager -l Thermald.service

相关内容