I have been trying to get logging to work on AWS Cloudwatch but have been unsuccessful so far. I am running a python flask backend on Fargate and handling logging through Cloudwatch. Only error messages are showing up however and nothing about the logs I have inserted. I will get error messages on cloudwatch and startup messages but no logs.
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with windowsapi reloader
* Debugger is active!
* Debugger PIN: 222-692-161
* Running on http://0.0.0.0:6000/ (Press CTRL+C to quit)
127.0.0.1 - - [03/Nov/2020 09:47:23] "GET /health HTTP/1.1" 200 -
This is shown on Cloudwatch, the flask startup dialogue and messages that the healthcheck query worked properly/ However no logs from within my health check. I have tried 2 strategies.
- The logging library
import logging
logger = logging.getLogger(level=logging.INFO)
log.info("This is an informative log")
and I have also define a print function to send data to stderr so I could have cloudwatch pick it up
def eprint(cls, *args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
eprint("this is another informative log")
I am not sure why neither of these solutions is working as Cloudwatch should pick up on data sent to stderr. Is there a way to enable Cloudwatch logs in a few lines of code and as minimally invasive as possible?
Thank you in advance!