2
I made a small log manager. It’s for something simple, so how is it fit. every day I want to delete and generate a new one, but my code is showing the following error:
The file is already being used by another process: 'test.log'
def manage_log():
try:
logging.basicConfig(filename=f"teste.log", level=logging.INFO)
arquivo = open("teste.log")
arq = arquivo.read()
arquivo.close()
dia = str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%d'))
if f'[{dia}]' not in arq:
logging.info(f" [{str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%d'))}] ")
elif arq[11:14] != dia:
os.remove("teste.log")
except Exception as e:
print(f"\033[1;31;mmanage_log error: {e}\033[;;m")