日志 Logging

日志记录了错误、警告、事件信息等,为后续调试作为参考。

日志层级

日志信息按严重性从低到高,可以分为:

  1. 信息
  2. 调试
  3. 警告
  4. 错误

日志聚合器

当你的应用在多台服务器上跑的时候,如果有一个“日志聚合器”作为监控工具会很有帮助。可以配置该工具,把系统和应用的日志发送给你查看、检索、监控,还可以设置个性化的警告,用于警示某些特定问题的发生。

开源日志聚合器

  • Sentry started as a Django-only exception handling service but now has separate logging clients to cover almost all major languages and frameworks. It still works really well for Python-powered web applications and is often used in conjunction with other monitoring tools. Raven is open source Python client for Sentry.
  • Graylog2 provides a central server for log aggregation as well as a GUI for browsing and searching through log events. There are libraries for most major languages, including python. Saves data in Elasticache.
  • Logstash Similar to Graylog2, logstash offers features to programmatically configure log data workflows.
  • Scribe A project written by Facebook to aggregate logs. It’s designed to run on multiple servers and scale with the rest of your cluster. Uses the Thrift messaging format so it can be used with any language.

日志云服务

  • Loggly is a third party cloud based application that aggregates logs. They have instructions for every major language, including python. It includes email alerting on custom searches.
  • Splunk offers third party cloud and self hosted solutions for event aggregation. It excels at searching and data mining any text based data.
  • Papertrail is similar to both Loggly and Splunk and provides integration with S3 for long term storage.
  • Raygun logs errors and provides immediate notification when issues arise.
  • Scalyr provides log aggregation, dashboards, alerts and search in a user interface on top of standard logs.
  • There is a hosted version of Sentry in case you do not have the time to set up the open source project yourself.

日志资源

日志学习清单

  1. 学习如何把日志整合到你的web框架里
  2. 确保错误和异常信息被日志记录,并存储于一个地方供你查看和检索。