Skip to content

How to redirect logging to files in a CherryPy app #1906

Answered by webknjaz
Wissperwind asked this question in Q&A
Discussion options

You must be logged in to vote

Sounds like you patched stderr/out after CherryPy got the pointers to the old objects. Also, I think patching global objects like that is rather bad.

FWIW it sounds like you forgot to configure or disable logging per https://docs.cherrypy.org/en/latest/basics.html#logging:

from pathlib import Path

THIS_SCRIPT_DIR = Path(__file__).parent.resolve()

cherrypy.config.update({
    'log.screen': False,
    'log.access_file': str(THIS_SCRIPT_DIR / 'stdOut.txt'),
    'log.error_file': str(THIS_SCRIPT_DIR / 'stdErr.txt'),
})

Also, note that you could set the environment to production per https://docs.cherrypy.org/en/latest/config.html#environments and that sets 'log.screen': False by default:

che…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by webknjaz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1905 on March 30, 2021 08:56.