Railway python questions
duhby
HOBBYOP

2 years ago

  • 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?

0 Replies

duhby
HOBBYOP

2 years ago

d7821c9a-e8f2-46c4-baee-82ab47fc0ae8


brody
EMPLOYEE

2 years 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.


duhby
HOBBYOP

2 years ago

ah it does seem to remove it, it just takes a minute

1221248589192237300


duhby
HOBBYOP

2 years ago

and thanks, I'll look into it


brody
EMPLOYEE

2 years 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


duhby
HOBBYOP

2 years 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!!!")

output:

1221323589547200500


brody
EMPLOYEE

2 years ago

awsome, thanks for coming back with that info!!


angobello
PRO

2 years ago

thanks for this


Loading...