I am trying to implement a python log rotation.
I have the following code to set up my logs:
logger = logging.getLogger("Log Rotate")
logger.setLevel(logging.DEBUG)
#set up file logging output
fh = logging.FileHandler(log)
fh.setLevel(logging.DEBUG)
#set up console output
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
fh.setFormatter(formatter)
#set up log rotate
lr = RotatingFileHandler(log, maxBytes=3000, backupCount=2)
# add the handlers to logger
logger.addHandler(ch)
logger.addHandler(fh)
logger.addHandler(lr)
When this is run, i am getting an error that the process cannot access the file because it is being used...
So to me, I think this is because it is trying to create a new log whilst it's writing to it, so windows is preventing it.
Is there a way around this?
Any help would be appreciated.