Reputation: 297
logzero sends all entry logs to a file, but also to stdout. Is there a way to avoid polluting the stdout?
I want to do this in Python. I don't want to call my script and redirect its output to /dev/null, because if I do so I won't be able to print useful messages to stdout.
EDIT: As @blues pointed out logzero sends lines to stderr, not stdout.
Upvotes: 3
Views: 776
Reputation: 5195
logzero does not actually send any logs to stdout, they are being sent to stderr. So you could redirect them to /dev/null without affecting your regular output.
But there is also a kwarg for logzero to not use this handler at all:
import logzero
logger = logzero.setup_default_logger(disableStderrLogger=True)
logzero.logfile('zero.log')
logger.info('appears in file but not on terminal')
I would however recommend instead to just use the native python logging module, as it is actually easier to setup for just filelogging:
import logging
logging.basicConfig(filename='logging.log', level='DEBUG')
logging.info('will be logged to file')
Upvotes: 4