Django runserver日志输出到文件中

时间:2022-03-22 13:55:25

How to print logs that come from python manage.py runserver into a log file (instead of showing inside a console).

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

This is the example of log that I want to be saved into a log file:

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

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.

执行系统检查...系统检查发现没有问题(0静音)。 2015年11月19日 - 01:37:54 Django版本1.8.5,使用设置'simpatize.settings'启动开发服务器http://127.0.0.1:8000/使用CONTROL-C退出服务器。

1 个解决方案

#1


0  

write the log to file log.txt in C:\dev\appName:

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

logger = logging.getLogger()

logger = logging.getLogger()

fh = logging.FileHandler('.\log.txt')

fh = logging.FileHandler('。\ log.txt')

logger.addHandler(fh)

logger.addHandler(FH)

#1


0  

write the log to file log.txt in C:\dev\appName:

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

logger = logging.getLogger()

logger = logging.getLogger()

fh = logging.FileHandler('.\log.txt')

fh = logging.FileHandler('。\ log.txt')

logger.addHandler(fh)

logger.addHandler(FH)