10

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.

  1. 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!

Josh Zwiebel
  • 883
  • 1
  • 9
  • 30
  • You don't need to change your application to log to Cloudwatch - what is the `"logConfiguration"` in your task? – Fermin Jan 31 '23 at 12:51

1 Answers1

0

As far as I am aware, your messages to stderr or stdout will not automatically show up, because you are not connected to a log stream.

If you use boto3 for instance, you can connect to your aws resource and then it can write the output to the logstream. but without this connection, my guess is that its just writing to the node itself and then exists once completed.

See https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/logs.html for more info

MrFronk
  • 382
  • 5
  • 23