Django runserver日志输出到文件中

时间:2015-11-19 01:46:43

标签: python django

如何将来自python manage.py runserver的日志打印到日志文件中(而不是显示在控制台内)。

这是我想要保存到日志文件中的日志示例:

Performing system checks... System check identified no issues (0 silenced). November 19, 2015 - 01:37:54 Django version 1.8.5, using settings 'simpatize.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.

1 个答案:

答案 0 :(得分:0)

将日志写入log.txt中的文件C:\dev\appName

logger = logging.getLogger()
fh = logging.FileHandler('.\log.txt')
logger.addHandler(fh)