aws-cloudformation-templates
aws-cloudformation-templates copied to clipboard
Logging error when libraries use root logger in crhelper.py
I'm getting an error when libraries are attempting to log
response = self.requests.get(url, auth=self._get_auth())
File "/var/task/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/var/task/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/var/task/requests/sessions.py", line 524, in request
resp = self.send(prep, **send_kwargs)
File "/var/task/requests/sessions.py", line 637, in send
r = adapter.send(request, **kwargs)
File "/var/task/requests/adapters.py", line 449, in send
timeout=timeout
File "/var/task/urllib3/connectionpool.py", line 588, in urlopen
conn = self._get_conn(timeout=pool_timeout)
File "/var/task/urllib3/connectionpool.py", line 248, in _get_conn
return conn or self._new_conn()
File "/var/task/urllib3/connectionpool.py", line 205, in _new_conn
self.num_connections, self.host, self.port or "80")
File "/var/lang/lib/python3.6/logging/__init__.py", line 1294, in debug
self._log(DEBUG, msg, args, **kwargs)
File "/var/lang/lib/python3.6/logging/__init__.py", line 1442, in _log
self.handle(record)
File "/var/lang/lib/python3.6/logging/__init__.py", line 1452, in handle
self.callHandlers(record)
File "/var/lang/lib/python3.6/logging/__init__.py", line 1514, in callHandlers
hdlr.handle(record)
File "/var/lang/lib/python3.6/logging/__init__.py", line 863, in handle
self.emit(record)
File "/var/runtime/awslambda/bootstrap.py", line 446, in emit
msg = self.format(record)
File "/var/lang/lib/python3.6/logging/__init__.py", line 838, in format
return fmt.format(record)
File "/var/lang/lib/python3.6/logging/__init__.py", line 578, in format
s = self.formatMessage(record)
File "/var/lang/lib/python3.6/logging/__init__.py", line 547, in formatMessage
return self._style.format(record)
File "/var/lang/lib/python3.6/logging/__init__.py", line 391, in format
return self._fmt % record.__dict__
KeyError: 'requestid'
I believe this is caused because the logger is attempting to obtain the requestid field, but this is only provided as an adaptor
https://github.com/awslabs/aws-cloudformation-templates/blob/master/community/custom_resources/python_custom_resource_helper/crhelper.py#L49
When the library does logging.getlogger(__name__), it retrieves the root logger, not the 'adapted' logger. Is this correct? Is it supposed to work this way?
Hey @jaymccon -- any thoughts on this?
I realize it has been three months and you may have moved on as there doesn't seem to be much activity on this project, but #157 may be related to your issue.
Did anyone ever resolve this bug?
The implementation in this repository has been deprecated in favor of https://github.com/aws-cloudformation/custom-resource-helper which has a richer feature set, is cleaner to implement and can be installed as a pip module.