I'm running a CLI on an EC2 server (Amazon Linux image), which I let run indefinitely with the screen terminal multiplexer. My program queries an API continuously and logs the current state to stdout:
The CLI logs encounters error occasionally, and it logs them, but when I SSH back into the EC2 server and recover the screen session, I see the latest logs only.
How can I keep track of everything printed to stdout, so I can inspect them later? CloudWatch?
Don't just dump the output to stdout, maybe it would be better to also send it and stderr to a file. If you want to not need to log into the instance to check the results you can forward them to a CloudWatch Loggroup and check from the console.
The updated version of the CW agent can collect logs via OpenTelemetry APIs, and you can do other fancy things with it. https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html