以下是我在 django settings.py文件中使用的日志记录片段。所有的 GET、POST 请求都被写入日志,但是当我写logger.info("print something") 时,它没有在控制台和日志文件中打印/捕获
请建议一种解决方法来捕获logger.info()日志
视图.py
import logging
logger = logging.getLogger(__name__)
def custom_data_generator(request):
logger.info("print somethig") # NOT GETTING CAPTURED IN LOG FILE
return somethig
settings.py(在 settings.py 文件中的DEBUG = True和DEBUG_MODE = False )
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '[%(asctime)s] %(levelname)s|%(name)s|%(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
},
'handlers': {
'applogfile': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': '/home/mahesh/Documents/refactor/unityapp/unity/media/myproject.log',
'backupCount': 10,
'formatter': 'simple',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
}
},
'loggers': {
'django': {
'handlers': ['applogfile', 'console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
}
}
}
生成的日志数据如下
[2020-07-07 11:43:25] ERROR|django.server|"GET /a11y/project-dashboard/?
refnum=ACGLOBAL&env_id=4 HTTP/1.1" 500 92016
[2020-07-07 12:05:21] INFO|django.server|"GET /admin/ HTTP/1.1" 200 59501
[2020-07-07 12:05:21] INFO|django.server|"GET /admin/ HTTP/1.1" 200 59501
[2020-07-07 12:05:21] INFO|django.server|"GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
[2020-07-07 12:05:21] INFO|django.server|"GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
[2020-07-07 12:05:21] INFO|django.server|"GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[2020-07-07 12:05:26] INFO|django.server|"GET /admin/accessibility/axe_json/ HTTP/1.1" 200 1886434
[2020-07-07 12:05:27] INFO|django.server|"GET /admin/jsi18n/ HTTP/1.1" 200 3223
[2020-07-07 12:05:27] INFO|django.server|"GET /static/admin/js/vendor/jquery/jquery.js HTTP/1.1" 200 280364
[2020-07-07 12:05:27] INFO|django.server|"GET /static/admin/js/vendor/xregexp/xregexp.js HTTP/1.1" 200 128820
[2020-07-07 12:05:34] INFO|django.server|"GET /admin/accessibility/axe_json/?page_id=https%3A%2F%2Fjobs.chegg.com%2Fapplythankyou HTTP/1.1" 200 1868950
[2020-07-07 12:05:35] INFO|django.server|"GET /admin/jsi18n/ HTTP/1.1" 200 3223