pythonpython-3.xflaskloggingchalice

How to print log in pytest using AWS Chalice framework?


How to print log in pytest using AWS Chalice framework?

The log prints everything if we use custom logger

import logging

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

Run test with log-level (Working)

pytest --log-cli-level=DEBUG

If I use AWS chalice log

import logging

from chalice import Chalice

app = Chalice(app_name='demolog')
# Enable DEBUG logs.
app.log.setLevel(logging.DEBUG)


@app.route('/')
def index():
    app.log.debug("This is a debug statement")
return {'hello': 'world'}

The same test command is not printing any log

pytest --log-cli-level=DEBUG

Any help?


Solution

  • Make Sure your Chalice instance is in debug and you can also turn off configure_logs

    app=Chalice(app_name="MyApp", debug=True, configure_logs=False)
    

    Put your debug and configure_logs on environment variables and then you can control them based on local/dev/stage/prod environments.