Adding a function to clean up log files

This commit is contained in:
Dom 2024-07-16 15:11:53 +01:00
parent fe25701659
commit f75d61d70b
2 changed files with 10 additions and 2 deletions

View File

@ -1,4 +1,4 @@
from log import log
from log import log, cleanLogs
from timeOperations import isInboundShipmentPlanWithinSpecifiedDelta
from amazonAPI import getAccessToken, getInboundShipmentData, getInboundShipmentPlans, getInboundShipmentPlan, getProductName
from sentNotifications import isInboundShipmentPlanIDInSentNotifications, updateSentNotifications
@ -42,4 +42,5 @@ def parseInboundShipmentPlans():
updateSentNotifications(inboundShipmentPlanID)
if __name__ == '__main__':
cleanLogs()
parseInboundShipmentPlans()

9
log.py
View File

@ -1,4 +1,6 @@
import logging
import os
from datetime import datetime
def log(log_message, level):
@ -23,4 +25,9 @@ def log(log_message, level):
logger.addHandler(file_handler)
log_message_types[level](log_message)
log_message_types[level](log_message)
def cleanLogs():
for filename in sorted(os.listdir('logs/'))[:-5]:
filenameWithPath = os.path.join('logs/', filename)
os.remove(filenameWithPath)