clearing log file using Django

Viewed 14

I am new to Django. I am trying to log the info messages to a log file and clear it every 10 mins. I tried the below code in settings.py

'handlers': {
    'file': {
        'level': 'INFO',
        'class': 'logging.handlers.TimedRotatingFileHandler',
        'filename': os.path.join(BASE_DIR,'Logfile.log'),
        'when': 'M',
        'interval': 10,
        'backupCount': 10,
        'formatter': 'simple'
    },
},

'loggers': {
    'django': {
        'handlers': ['file'],
        'level': 'INFO',
        'propagate': True, 
    }, 
    'main':{
        'handlers': ['file'],
        'level': 'INFO',
        'propagate': True,
         
    }   
},

I face error stating PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'D:\Folder\LogFile.log' -> 'D:\Folder\LogFile.log.2022-02-24_12-08'

I understand the error that I can't rename a file that's open. I would like someone to help me in resolving this and helping me clear the log file.

Thanks in advance

0 Answers
Related