Page 1
江西唐门计算机系统有限公司 1
Learning Python logging module
@dotecho2012/03/24
Page 3
江西唐门计算机系统有限公司 3
使用 Logging模块的好处
无需安装任何第三方库 (logging在标准库里面 ) 很方便的为应用程序或模块或包记录日志 日志信息分级 成熟,众多使用者,稳定 定制自己所需的 handler
Page 4
江西唐门计算机系统有限公司 4
Logging模块的设计
Loggers提供应用程序直接使用的接口 Handlers发送日志到适当的位置 Filters提供过滤日志输出 Formatters指定具体日志的最终显示
Page 5
江西唐门计算机系统有限公司 5
Logging基本使用
a simple example log to a file logging from multiple modules logging variable data Changing the format of displayed messages Displaying the date/time in messages
Page 8
江西唐门计算机系统有限公司 8
logging from multiple modules
Page 10
江西唐门计算机系统有限公司 10
Changing the format of displayed messages
Page 11
江西唐门计算机系统有限公司 11
Displaying the date/time in messages
Page 12
江西唐门计算机系统有限公司 12
Logging Handlers
Filehandler StreamHandler WatchFileHandler SocketHandler
Page 13
江西唐门计算机系统有限公司 13
Logging Config
Directly in code File conf Dictconf
Page 14
江西唐门计算机系统有限公司 14
多进程日志处理
单进程 server处理 WatchedFileHandler + cron job
Page 15
江西唐门计算机系统有限公司 15
Logging in Flask
http://flask.pocoo.org/docs/quickstart/#logging http://flask.pocoo.org/docs/errorhandling/ extend log handler to tpage.
Page 16
江西唐门计算机系统有限公司 16
Logging in Dajngo
https://docs.djangoproject.com/en/1.4/topics/logging/
Page 17
江西唐门计算机系统有限公司 17
tlogserver: A simple logging sockethandler Server
简单及方便 日志集中化管理