日志 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. 确保错误和异常信息被日志记录,并存储于一个地方供你查看和检索。

代码矩阵 Code Metrics

代码矩阵由静态代码分析工具生成,用于分析代码复杂度。

为什么代码矩阵重要?

代码矩阵允许开发者找出代码库中需要重构的部分。

开源代码矩阵项目

代码矩阵云服务

代码矩阵资源

单元测试 Unit testing

单元测试只测试单个程序或单个函数的正确性。它的理念是,如果每个函数单元和程序单元都能正常运作,那么把它们整合到一起,能够正常工作的几率会更大些。

为什么单元测试重要?

当多个程序联合工作的时候,要找出哪里有bug是不容易的。因此最好事先一个程序一个程序的测试,好找出bug所在。

单元测试工具

Python有许多单元测试工具。有些工具比如pytest,替代了内建的unittest框架。许多工具也能用于整合测试。

单元测试资源

测试

只有经过测试,才能知道软件是否按照设想正常运行,并告诉开发者该如何修改。

为什么测试很重要?

当软件规模增大到一定程度,任何一个人都没有办法掌握其他人对该软件所做的修改有哪些。自动测试是唯一有效保证软件可靠的方法。许多大型软件的失败,原因都是因为缺乏充分的测试。

测试有许多层面。单个函数或单个程序的测试,被称为单元测试 unit testing。同时测试一个应用里的多个程序被称为整合测试。此外还有用户界面测试、装载测试、数据库测试、浏览器测试。

Python测试

Python是一种动态语言,而不是静态语言,测试在Python中的重要性更大。

测试资源