View all console output in deployment logs

I don’t know if this is common knowledge but I just figured it out. For deployed python flask apps:

print('Hello, world!', flush=True)

‘Hello world!’ shows up in the deployment log. So apparently you can see console output in the logs if you set the flush flag to True.


Isn’t flushing, like, slow? & you shouldn’t use it when you don’t have to?

I’m guessing that python buffering the output was causing issues, flush just bypasses the buffer.

1 Like

On a side note, you could overwrite the print function to always flush:

bkpPrint = print

def print(*args, **kwargs):
    bkpPrint(*args, **kwargs, flush = True)
1 Like

if you don’t want to flush, using stderr might also work:

from sys import stderr

print("Hello, world!", file=stderr)

and one way to do this so that it only works in a deployment is to define the function based on if "REPLIT_DOMAINS" in os.environ

1 Like