Python logging log configuration, how not to output to the console

my log configuration is as follows: the log is automatically output to the console at runtime and suspended with nohup, and the corresponding output will also output nohup.out
while my.log will also have the correct log output
the log output format of my.log is correct, and the log output to the console is the same as the log generated by ide (pychram) debugging

logHandler = TimedRotatingFileHandler("logs/my.log", when="midnight")
logFormatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
logHandler.setFormatter(logFormatter)
logger = logging.getLogger("myapp")
logger.addHandler(logHandler)
logger.setLevel(logging.INFO)

how should I modify it?

Apr.11,2021

there is no need to change the python code, it is better to modify the startup script, you can define the output to / dev/null . As follows:

-sharp!/usr/bin/env bash

nohup  > /dev/null 2>&1 &

explain in detail:
> / dev/null is to redirect the standard output stream (code 1) to a device that does not exist, that is, to discard it directly. 2 > & 1 is to put the standard error stream (code 2) into the standard output stream (code 1), that is, the output stream is a mixture of standard output and standard error. In this way, both standard output and standard error are discarded. The last & is started in the background.

Menu