Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If your logger uses a own format include "aws_request_id", an error will occur. #40

Closed
belgh opened this issue Nov 8, 2018 · 3 comments

Comments

@belgh
Copy link

belgh commented Nov 8, 2018

In the production Lambda environment I am changing the format of the root logger.

Original format in aws lambda:

print(str( logging.getLogger('').handlers[0].formatter._fmt ))
#-> [%(levelname)s]	%(asctime)s.%(msecs)dZ	%(aws_request_id)s	%(message)s

Format I changed:

formatter = logging.Formatter(
  fmt='%(asctime)s.%(msecs)03d [%(aws_request_id)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s\n',
  datefmt='%Y-%m-%d %H:%M:%S'
)
handler = logging.getLogger('').handlers[0]
handler.setFormatter(formatter)

and when this script is executed, the following error occurs.

--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib64/python3.6/logging/__init__.py", line 992, in emit
    msg = self.format(record)
  File "/usr/lib64/python3.6/logging/__init__.py", line 838, in format
    return fmt.format(record)
  File "/usr/lib64/python3.6/logging/__init__.py", line 578, in format
    s = self.formatMessage(record)
  File "/usr/lib64/python3.6/logging/__init__.py", line 547, in formatMessage
    return self._style.format(record)
  File "/usr/lib64/python3.6/logging/__init__.py", line 391, in format
    return self._fmt % record.__dict__
KeyError: 'aws_request_id'

Sorry for the report only.

@yxd-hde
Copy link
Contributor

yxd-hde commented Nov 8, 2018

Would you please post the log output of a Lambda function call on AWS here?

@belgh
Copy link
Author

belgh commented Nov 8, 2018

It is described below.
(It is a log output by business, so I am editing it)

2018-11-07 07:43:19.314 [74b70065-a260-c148-a552-1d024c701016] INFO [module_name:100] hello hoge

@yxd-hde yxd-hde mentioned this issue Nov 8, 2018
@yxd-hde
Copy link
Contributor

yxd-hde commented Nov 20, 2018

Fixed by #41 .

@yxd-hde yxd-hde closed this as completed Nov 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants