Django自定义日志仅记录自定义消息,不包含错误消息

时间:2019-11-29 04:29:55

标签: django

我已经创建了一个自定义日志,我只想存储自定义消息。但是,当此文件有一些错误时,此日志还将记录错误日志。有人知道如何实现这一目标吗? (我将单独的系统错误日志保存到其他文件。)

from django.http import HttpResponse
import  logging
logging.basicConfig(filename='storage/log/trademoney.log', level=logging.INFO, format='%(asctime)s : %(message)s')

def set_log(request):
    logging.info('ohla') <--custom log
    return HttpResponse(ohla) <--system error (undefined)

日志(我希望此自定义日志仅存储我设置的信息,我不希望系统错误日志)

2019-11-29 12:22:52,888 : ohla <----I only want this log (I don't want system error log)

2019-11-29 12:22:52,895 : Internal Server Error: /blog/zh_TW/log/
Traceback (most recent call last):
  File "C:\Python3\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Python3\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Python3\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\xampp\htdocs\python\demo\blog\modules\log.py", line 7, in set_log
    return HttpResponse(ohla)
NameError: name 'ohla' is not defined
2019-11-29 12:22:52,897 : "GET /blog/zh_TW/log/ HTTP/1.1" 500 27

0 个答案:

没有答案