I have a such logger initializing function:
def generate_logger():
import logging
LOG_FILENAME = os.path.join(PROJECT_DIR, "mylog.log")
FORMAT = "%(asctime)s : %(message)s"
logger = logging.getLogger()
logger.setLevel(logging.INFO)
fh = logging.FileHandler(LOG_FILENAME)
formatter = logging.Formatter(FORMAT)
fh.setFormatter(formatter)
logger.addHandler(fh)
return logger
And at some part of my code I have such exception catching:
logger = generate_logger()
except AttributeError:
logger.error('Opps we got an error')
Weirdly I get same error written 2 times and it can be caugh only once, once I change logger.error('Opps we got an error')
with print "test"
, I get "test" printed once.
What can be the problem and the solution.
Regards