Python stdin stderr logging
Logging in Python is quite straight forward, except for by the BasicConfig writes to stderr and not to stdout
|
|
This can cause info logs to be written to stderr and in AWS Glue it ends up in the error logs.
Setup logs to stdout
|
|
Using print()
Clearly using logging is a but complicated for some usecases.
print() in python writes to stdout by default. But we can make it write to stderr.
|
|
AWS Glue Python Shell logs
You can use print statements in your Glue Python Shell job for logging. Glue captures stdout and stderr by default.
There is no need to setup a logger in Glue Python Shell job.
Redirecting stderr and stdout
Most shells will show you stdout and stderr logs in the console. You can redirect error logs and stdout logs into different files.
Use 1> to redirect stdout and 2> to redirect stderr.
>> can be used to append operation
|
|
References
- https://stackoverflow.com/questions/5574702/how-to-print-to-stderr-in-python
- https://docs.python.org/3.0/whatsnew/3.0.html
- https://stackoverflow.com/questions/7901517/how-to-redirect-stderr-and-stdout-to-different-files-in-the-same-line-in-script
- https://stackoverflow.com/questions/14058453/making-python-loggers-output-all-messages-to-stdout-in-addition-to-log-file