Python deployment showing wrong logging type
I have
logging.info()
to log some information about my application while running but for some reason, Railway show it as ERROR
, which is quite annoying (as seen in the image).
This is how I handle the log for my deploy:
Is there anyway to fix this?Solution:Jump to solution
logging.info() logs to stderr, thus it's being treated as an error, two options - log to stdout, or use json structured logging (railway has amazing support for structured logging)
9 Replies
Project ID:
e1ece322-0918-4d47-a1fd-f7d31ed137fa
The project ID is
e1ece322-0918-4d47-a1fd-f7d31ed137fa
Solution
logging.info() logs to stderr, thus it's being treated as an error, two options - log to stdout, or use json structured logging (railway has amazing support for structured logging)
Can you explain more about the json structured logging thing? First time hearing about this.
there are many great resources online about it that would do a better job at describing it than I could, but tl;dr you would use a logging library that supports logging in json, your log message and level would be printed to the console as attributes in a json object and railway will parse the message and level out, then railway will colour the log accordingly to the level
Ah, I get that idea now.
The first option you mentioned, if I set the log to stdout, then imagine if it is actually an
ERROR
, Railway still treat it as with the stdout, which no error color?correct
here's an example of railways support for structured logging, this of course contains more than just a message and level, and that's how railway will display additional attributes
you can also filter your logs by those attribute values
Ah, gotcha.
I think for now, I will try to display the information with stdout, and handle the error through stderr. Later, when I have time, I will learn how to use the structured logging. Thanks for the help, Brody. :)
no problem!