由于项目的需要,现在需要通过一种方式,让Python程序能够在会话退出后继续在后台运行,并将屏幕的输出重定向到文件中去。
本文的示例代码已经上传到http://download.youkuaiyun.com/detail/mrbcy/9789067
参考资料
http://blog.youkuaiyun.com/loonger_leon/article/details/5764552
http://www.cnblogs.com/hester/p/5575658.html
测试程序
先写一个测试程序,用于输出日志和打印到控制台。
#-*- coding: utf-8 -*-
import logging
import time
from logging.handlers import RotatingFileHandler
def func():
init_log()
while True:
print "output to the console"
logging.debug("output the debug log")
logging.info("output the info log")
time.sleep(3);
def init_log():
logging.getLogger().setLevel(logging.DEBUG)
console = logging.StreamHa