Current Behavior
When adding a logger.info('Logging message') anywhere in my code, the request returns a response without a body. When I supress the logger.info calls, the body comes back.
Sample Code
service: image-to-template-api
provider:
name: aws
runtime: python3.7
region: ${env:REGION}
stage: ${env:STAGE}
functions:
process:
handler: handler.process
events:
- http:
path: process
method: post
exclude:
- node_modules/**
- tests/**
plugins:
- serverless-dotenv-plugin
- serverless-python-requirements
- serverless-offline
import json
import os
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def process(event, context):
logger.info('## ENVIRONMENT VARIABLES')
logger.info(os.environ)
logger.info('## EVENT')
logger.info(event)
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
Expected behavior/code
The body is still returned after adding loggers.
Environment
serverless version: v1.58.0serverless-offline version: 6.0.0-alpha.50node.js version: v10.13.0OS: macOS 10.15.1python version: v3.7.3thank you for filing this bug report @georgesbiaux ! yes, there seems to be an issue with python and logging.
@benjaminsims follow up from: #851
entry point for any "runner" (node, python, ruby) here:
https://github.com/dherault/serverless-offline/blob/ccb64177eb5a4d2b2d3b6c1f05045c1462e0bea7/src/lambda/handler-runner/HandlerRunner.js#L60
which runs: https://github.com/dherault/serverless-offline/blob/v6.0.0-alpha.52/src/lambda/handler-runner/invoke.py
as I mentioned, all of this is more or less based on the serverless local invoke implementation, I only rewrote it to use execa and some other small-ish changes.
to distinguish between payload I added: https://github.com/dherault/serverless-offline/blob/3d8c35a16d0bc83453a5473ba6a9c503ae294597/src/lambda/handler-runner/invoke.py#L94
let me know if you have any other questions. there's some preliminary setup steps here: https://github.com/dherault/serverless-offline/blob/master/CONTRIBUTING.md (probably needs to be improved as well.) don't hesitate to ask.
Using sls invoke local, both logging output and the actual intended output was printed to stdout.
This only occurs when using standard Python logging; using print() statements will not cause the response to be empty (however the printed text will not appear in the sls offline logs, though it will when using invoke local).
I also tried removing the logging.basicConfig() call from invoke.py, but this made no difference.
I assume it's something to do with loggers fighting over stdout, but I haven't yet been able to get the serverless-offline running in development mode to investigate further.
@georgesbiaux @benjaminsims it seems we ignored stdout (with e.g. print()) from python other than the handler payload. python logging in turn went to stderr and that ignored the handler payload as well.
both should be [hopefully] fixed now.
@dnalborczyk Seems fixed, thank you!
Most helpful comment
@georgesbiaux @benjaminsims it seems we ignored
stdout(with e.g. print()) frompythonother than the handler payload. python logging in turn went tostderrand that ignored the handler payload as well.both should be [hopefully] fixed now.