Logging
一句话解释
Logging 是练习的 recording application 事件 and 错误到 centralized storage for 调试 and analysis.
用大白话说
Logging is the practice of recording what your application does — events, errors, warnings, info messages — so you can debug problems and understand behavior. In a containerized environment, logs are especially important because you cannot SSH into a container to look around.
In DevOps, logs from all your services are collected and sent to a centralized log store where you can search and analyze them. This is crucial because in a microservices architecture, a single user request might touch many services, and you need to trace the problem across all of them.
Popular logging stacks include the ELK Stack (Elasticsearch, Logstash, Kibana) and Loki (by Grafana Labs). Logs are typically structured (JSON format) so they can be searched and filtered easily.
示例
# View logs from a Kubernetes Pod
kubectl logs my-app-pod
# View logs from a Docker container
docker logs my-container
# Tail logs in real-time
kubectl logs -f my-app-pod这些 commands show logs 从 Kubernetes Pod and Docker 容器. -f flag follows log 输出 in 真实-时间.
工作原理
- Applications write logs to stdout/stderr.
- A log collector (Fluentd, Filebeat) reads and forwards them.
- Logs are stored in a centralized store (Elasticsearch, Loki).
- You search and visualize logs using a tool like Kibana or Grafana.
常见混淆
容易混淆的对象: Monitoring
关键区别: Logging 记录 discrete 事件 (文本); monitoring collects numeric metrics (CPU, memory) over 时间. 两者都是 需要 for 完整 observability.
相关术语
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。