a year ago
Hi! I have a streamlit app on railway which uses the standard logging library to log stdout to railway.
I'm getting the messages into railway, but only that, the messages. I'm not getting the level severity or any extra attributes I put into my logs.
For example I may log something with:
logger.warning("message", extra={"context": "something"})
And in railway I see only the message in blue, as "INFO" (no warning, as I sent it) and I cant see the other attributes (in this case, 'context').
Am I doing something wrong?
Thanks!
9 Replies
a year ago
In the Message column in Observability, the raw column looks like:
WARNING - message
And, if I use: logger.error("message", extra={"context": "something"}), it will look like:
ERROR - message
In both cases, the log appears as "INFO" in the histogram, and if I click on the plus sign, to see details, i can see deployment, replica, service… but not my extra field, context.
a year ago
please send the raw json output of these logger functions, railway will not show you the raw log if it's json
a year ago
Sorry Brody, I think I dont understand.
What do you mean by raw json output? The logger function in python seems to be outputing only a "raw" string: "ERROR - message", but not a JSON.
Thanks in advance
a year ago
an example of what a raw json log message would look like would be this
{"time": "2010-01-01 12:34:56.0000", "level": "INFO", "message": "hello, world", "extra": {"context": "something"}}
run your app locally, if you don't see a raw json message like this in your terminal, Railway will not be able to properly parse your log attributes into a structure that you can look through in the log's context.
a year ago
Okay, so, if I manage to log a formatted json like that, is there any rules I have to follow so Railway is able to parse it?
Like naming conventions, or something like that?
a year ago
time
, message
/ msg
, and a level
attribute are all that's needed, besides of course being fully valid json
a year ago
Okay, will try it out. Thank you so much!
a year ago
Hello!
I know it has been 3 months but this may help someone: "The extra parameter is just ignored by the standard formatter."
You have to set a custom formatter if logging into the terminal and you want to see the arguments passed to the "extra" parameter, check this SO QA thread for extra info:
https://stackoverflow.com/questions/56559971/show-extra-fields-when-logging-to-console-in-python