R
Railway9mo ago
dubs

Railway python questions

- I heard when railway deploys a project after a git commit to the main branch, it's supposed to remove the previous deployment after it finishes, but when it's a python script (discord bot) it doesn't do that (the attached image is from using a template) - When using logging.getLogger().info("message"), railway flags it as an error in logs, but when using print("message") (not recommended to use) it's a normal log. Is there a way to fix this?
No description
No description
Solution:
old deployments will be removed, refresh. logs are red when logging to stderr, print() prints to stdout, i would highly recommend looking into JSON logging as railway has amazing support for it....
Jump to solution
9 Replies
Percy
Percy9mo ago
Project ID: d7821c9a-e8f2-46c4-baee-82ab47fc0ae8
dubs
dubsOP9mo ago
d7821c9a-e8f2-46c4-baee-82ab47fc0ae8
Solution
Brody
Brody9mo ago
old deployments will be removed, refresh. logs are red when logging to stderr, print() prints to stdout, i would highly recommend looking into JSON logging as railway has amazing support for it.
dubs
dubsOP9mo ago
ah it does seem to remove it, it just takes a minute
No description
dubs
dubsOP9mo ago
and thanks, I'll look into it
Brody
Brody9mo ago
the overlap is there as a default for websites/APIs to mitigate downtime, for discord bots that irrelevant, so you can disable the overlap by setting a service variable RAILWAY_DEPLOYMENT_OVERLAP_SECONDS to 0
dubs
dubsOP9mo ago
in case anyone else searches for this, there's a nice python library named structlog that can give you json logging functionality built in:
import structlog

structlog.configure(
processors=[
structlog.processors.add_log_level, # adds {"level" = "info"}
structlog.processors.EventRenamer("message"), # renames {"event": "hello"} to {"message": "hello"}
structlog.processors.JSONRenderer(), # outputs as json
]
)

logger: structlog.stdlib.BoundLogger = structlog.get_logger()

logger.debug("hello", key="value?")
logger.info("hi", key="value.")
logger.warn("hey :(", key="value!")
logger.error("oh no", key="value!!!")
import structlog

structlog.configure(
processors=[
structlog.processors.add_log_level, # adds {"level" = "info"}
structlog.processors.EventRenamer("message"), # renames {"event": "hello"} to {"message": "hello"}
structlog.processors.JSONRenderer(), # outputs as json
]
)

logger: structlog.stdlib.BoundLogger = structlog.get_logger()

logger.debug("hello", key="value?")
logger.info("hi", key="value.")
logger.warn("hey :(", key="value!")
logger.error("oh no", key="value!!!")
output:
No description
Brody
Brody9mo ago
awsome, thanks for coming back with that info!!
Krøn
Krøn9mo ago
thanks for this
Want results from more Discord servers?
Add your server