There is a logger path for production environment, but I want to put the logs in /tmp/ in unittests.
LOGGING_DIR = '/data0/bridge_logs_test/'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'default': {
'format': '{levelname}\t{asctime}\t{pathname}\t{lineno:d}\t{process:d}\t{message}',
'style': '{'
}
},
'handlers': {
'console_log_handler': {
'level': 'ERROR',
'class': 'logging.StreamHandler',
},
'backup_log_handler': {
'level': 'INFO',
'class': 'logging.handlers.WatchedFileHandler',
'filename': os.path.join(LOGGING_DIR, 'put.log'),
'formatter': 'default',
},
......
},
'loggers': {
'django': {
'handlers': ['console_log_handler', ],
'level': 'DEBUG',
'propagate': True,
},
'backup': {
'handlers': ['backup_log_handler', ],
'level': 'INFO',
'propagate': False,
},
......
},
}
And in unittests, I write:
from django.test import TestCase
class FaceAITestCase(TestCase):
def test_function1(self):
with self.modify_settings(LOGGING_DIR="/tmp/test_logs/"):
pass
When run the unittests, it reports:
ValueError: Unable to configure handler 'access_log_handler': [Errno 2] No such file or directory: '/data0/bridge_logs_test/access.log'