使用 watchtower 的 Django 日志记录在处理程序中得到了一个意外的关键字参数
Django logging with watchtower got an unexpected keyword argument in handler
我正在尝试使用 AWS CloudWatch 实现 django 日志记录,在创建用户并输入正确的字段后,按照网上散布的指南,我仍然遇到错误:
ValueError: Unable to configure handler 'watchtower': __init__() got an unexpected keyword argument 'boto3_session'
这是我的设置文件(日志配置):
boto3_connect_session = Session(
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
region_name=AWS_REGION_NAME
)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'aws': {
'format': u"%(asctime)s [%(levelname)-8s] %(message)s [%(pathname)s:%(lineno)d]",
'datefmt': "%Y-%m-%d %H:%M:%S"
},
'simple': {
'format': '[%(asctime)s %(module)s] %(levelname)s: %(message)s'
},
},
'handlers': {
'watchtower': {
'level': 'DEBUG',
'class': 'watchtower.CloudWatchLogHandler',
'boto3_session': boto3_connect_session,
# 'log_group': AWS_LOG_GROUP,
# 'stream_name': AWS_LOG_STREAM,
'formatter': 'aws',
},
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/tmp/logger.log',
'formatter':'simple'
},
},
'loggers': {
AWS_LOGGER_NAME: {
'level': 'DEBUG',
'handlers': ['watchtower'],
'propagate': False,
},
'local': {
'level': 'DEBUG',
'handlers': ['file'],
'propagate': False,
},
},
}
完整错误信息:
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib64/python3.6/logging/config.py", line 565, in configure
handler = self.configure_handler(handlers[name])
File "/usr/lib64/python3.6/logging/config.py", line 738, in configure_handler
result = factory(**kwargs)
File "/usr/local/lib/python3.6/site-packages/watchtower/__init__.py", line 203, in __init__
super().__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'boto3_session'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/usr/local/lib/python3.6/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
raise _exception[1]
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "/usr/local/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python3.6/site-packages/django/utils/log.py", line 76, in configure_logging
logging_config_func(logging_settings)
File "/usr/lib64/python3.6/logging/config.py", line 802, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib64/python3.6/logging/config.py", line 573, in configure
'%r: %s' % (name, e))
ValueError: Unable to configure handler 'watchtower': __init__() got an unexpected keyword argument 'boto3_session'
瞭望塔版本:
Name: watchtower
Version: 3.0.0
boto3 版本:
Name: boto3
Version: 1.13.3
我想不通问题出在哪里,大部分导游都用这个系统
提前致谢。
在官方的doc for watchtower with Django中,
中没有提到boto3_session
'watchtower': {
'level': 'DEBUG',
'class': 'watchtower.CloudWatchLogHandler',
'boto3_session': boto3_connect_session,
# 'log_group': AWS_LOG_GROUP,
# 'stream_name': AWS_LOG_STREAM,
'formatter': 'aws',
},
文档有 boto3_client
而不是 boto3_session
你能核对一下吗?
我正在尝试使用 AWS CloudWatch 实现 django 日志记录,在创建用户并输入正确的字段后,按照网上散布的指南,我仍然遇到错误:
ValueError: Unable to configure handler 'watchtower': __init__() got an unexpected keyword argument 'boto3_session'
这是我的设置文件(日志配置):
boto3_connect_session = Session(
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
region_name=AWS_REGION_NAME
)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'aws': {
'format': u"%(asctime)s [%(levelname)-8s] %(message)s [%(pathname)s:%(lineno)d]",
'datefmt': "%Y-%m-%d %H:%M:%S"
},
'simple': {
'format': '[%(asctime)s %(module)s] %(levelname)s: %(message)s'
},
},
'handlers': {
'watchtower': {
'level': 'DEBUG',
'class': 'watchtower.CloudWatchLogHandler',
'boto3_session': boto3_connect_session,
# 'log_group': AWS_LOG_GROUP,
# 'stream_name': AWS_LOG_STREAM,
'formatter': 'aws',
},
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/tmp/logger.log',
'formatter':'simple'
},
},
'loggers': {
AWS_LOGGER_NAME: {
'level': 'DEBUG',
'handlers': ['watchtower'],
'propagate': False,
},
'local': {
'level': 'DEBUG',
'handlers': ['file'],
'propagate': False,
},
},
}
完整错误信息:
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib64/python3.6/logging/config.py", line 565, in configure
handler = self.configure_handler(handlers[name])
File "/usr/lib64/python3.6/logging/config.py", line 738, in configure_handler
result = factory(**kwargs)
File "/usr/local/lib/python3.6/site-packages/watchtower/__init__.py", line 203, in __init__
super().__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'boto3_session'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/usr/local/lib/python3.6/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
raise _exception[1]
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "/usr/local/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python3.6/site-packages/django/utils/log.py", line 76, in configure_logging
logging_config_func(logging_settings)
File "/usr/lib64/python3.6/logging/config.py", line 802, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib64/python3.6/logging/config.py", line 573, in configure
'%r: %s' % (name, e))
ValueError: Unable to configure handler 'watchtower': __init__() got an unexpected keyword argument 'boto3_session'
瞭望塔版本:
Name: watchtower
Version: 3.0.0
boto3 版本:
Name: boto3
Version: 1.13.3
我想不通问题出在哪里,大部分导游都用这个系统
提前致谢。
在官方的doc for watchtower with Django中,
中没有提到boto3_session
'watchtower': {
'level': 'DEBUG',
'class': 'watchtower.CloudWatchLogHandler',
'boto3_session': boto3_connect_session,
# 'log_group': AWS_LOG_GROUP,
# 'stream_name': AWS_LOG_STREAM,
'formatter': 'aws',
},
文档有 boto3_client
而不是 boto3_session
你能核对一下吗?