R
Railway8mo 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
Percy8mo ago
Project ID: d7821c9a-e8f2-46c4-baee-82ab47fc0ae8
dubs
dubs8mo ago
d7821c9a-e8f2-46c4-baee-82ab47fc0ae8
Solution
Brody
Brody8mo 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
dubs8mo ago
ah it does seem to remove it, it just takes a minute
No description
dubs
dubs8mo ago
and thanks, I'll look into it
Brody
Brody8mo 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
dubs8mo 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
Brody8mo ago
awsome, thanks for coming back with that info!!
Krøn
Krøn8mo ago
thanks for this
Want results from more Discord servers?
Add your server