這些是一些示例設置,應確保將日誌寫入控制檯和文件。您可以添加/修改這個在你的開發設置:
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
},
},
'handlers': {
# this is what you see in runserver console
'console': {
'class': 'logging.StreamHandler',
'formatter': 'standard',
},
# this handler logs to file
#▼▼▼▼ this is just a name so loggers can reference it
'file': {
'class': 'logging.FileHandler',
# choose file location of your liking
'filename': os.path.normpath(os.path.join(BASE_DIR, '../../logs/django.log')),
'formatter': 'standard'
},
},
'loggers': {
# django logger
'django': {
# log to console and file handlers
'handlers': ['console', 'file'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'ERROR'), # choose verbosity
},
},
}
語法使用泊塢窗: CMD [ 「/ bin/sh的」, 「-c」,「/manage.py的runserver 0.0.0.0:3000> > log.log 2>&1「] – Vingtoft