I think you need to remove the logging.basicConfig call. This function adds another logging.StreamHandler , which is probably the one that prints messages you don't want to print.
To check this, you can look at the handlers attribute for the root logger (this is a list with all the handlers used) and check the number of logging.StreamHandlers . In addition, it is likely that a message with a level set to logging.ERROR is printed twice due to two logging.StreamHandler s.
My last tip is avoiding using logging.basicConfig if you are going to explicitly configure handlers in your code.
Edit: for completeness only, the source code for logging.basicConfig as follows:
if len(root.handlers) == 0: filename = kwargs.get("filename") if filename: mode = kwargs.get("filemode", 'a') hdlr = FileHandler(filename, mode) else: stream = kwargs.get("stream") hdlr = StreamHandler(stream) fs = kwargs.get("format", BASIC_FORMAT) dfs = kwargs.get("datefmt", None) fmt = Formatter(fs, dfs) hdlr.setFormatter(fmt) root.addHandler(hdlr) level = kwargs.get("level") if level is not None: root.setLevel(level)
where you can see that if filename not passed, logging.StreamHandler is created.
source share