The following code prints both to the console and to the specified log-file - why? How can I tell logger to only use the filehandler? I tried to disable printing to console by commenting out line 8 (logger.setLevel(logging.INFO)), but the result of that was that the log file was created but empty. (I'm using logger in main() and in the class defined in the file)
if __name__ == "__main__":
HOME_DIR = '/mydir'
LOG_FILENAME = HOME_DIR + '/my.log'
logging.info('Starting...')
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
fh = logging.FileHandler(LOG_FILENAME)
fh = logging.handlers.RotatingFileHandler(LOG_FILENAME,
maxBytes=10000,
backupCount=1,)
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
main()