Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
logging
#1
I am using logging in the following way, but the info log for which I have backup count as 20, I don't see 20th log file has 100MB oldest data in it ...similarly with 19th to 1st backup log...
My Objective: backup - 20 logs with a 100MB limit. The 20th log should contain the oldest data of 100MB size and so..on till 1st log contain recent old data while the main log file keeps getting updated with current logging data.

Can anyone please help me out on why I am seeing odd behavior in saving old data in backup log files
Note: I am importing the below log python module in all python scripts I have to take care of centralized logging
Output:
-rw-r--r-- 1 root root 7669351 Oct 17 06:57 li_wf_integration_error.log -rw-r--r-- 1 root root 91802107 Oct 17 07:18 li_wf_integration_info.log -rw-r--r-- 1 root root 327 Oct 17 07:11 li_wf_integration_info.log.1 -rw-r--r-- 1 root root 858 Oct 17 07:11 li_wf_integration_info.log.10 -rw-r--r-- 1 root root 327 Oct 17 07:11 li_wf_integration_info.log.11 -rw-r--r-- 1 root root 315 Oct 17 07:11 li_wf_integration_info.log.12 -rw-r--r-- 1 root root 54206 Oct 17 07:11 li_wf_integration_info.log.13 -rw-r--r-- 1 root root 1144 Oct 17 07:11 li_wf_integration_info.log.14 -rw-r--r-- 1 root root 1147 Oct 17 07:11 li_wf_integration_info.log.15 -rw-r--r-- 1 root root 1908 Oct 17 07:11 li_wf_integration_info.log.16 -rw-r--r-- 1 root root 1146 Oct 17 07:11 li_wf_integration_info.log.17 -rw-r--r-- 1 root root 1711 Oct 17 07:11 li_wf_integration_info.log.18 -rw-r--r-- 1 root root 2126 Oct 17 07:11 li_wf_integration_info.log.19 -rw-r--r-- 1 root root 327 Oct 17 07:11 li_wf_integration_info.log.2 -rw-r--r-- 1 root root 1729 Oct 17 07:11 li_wf_integration_info.log.20 -rw-r--r-- 1 root root 327 Oct 17 07:11 li_wf_integration_info.log.3 -rw-r--r-- 1 root root 327 Oct 17 07:11 li_wf_integration_info.log.4 -rw-r--r-- 1 root root 327 Oct 17 07:11 li_wf_integration_info.log.5 -rw-r--r-- 1 root root 2598 Oct 17 07:11 li_wf_integration_info.log.6 -rw-r--r-- 1 root root 3565 Oct 17 07:11 li_wf_integration_info.log.7 -rw-r--r-- 1 root root 16487 Oct 17 07:11 li_wf_integration_info.log.8 -rw-r--r-- 1 root root 496 Oct 17 07:11 li_wf_integration_info.log.9
import logging
from logging.handlers import RotatingFileHandler

log = logging.getLogger("LogInsightWavefrontIntegration")
formatter = logging.Formatter("%(asctime)s %(name)s %(levelname)s %(message)s")

LOG_INFO_FILE_NAME = "/var/log/li_wf_integration_info.log"
LOG_ERROR_FILE_NAME = "/var/log/li_wf_integration_error.log"

info_handler = RotatingFileHandler(
    LOG_INFO_FILE_NAME, mode="a", maxBytes=100 * 1024 * 1024, backupCount=20
)
info_handler.setFormatter(formatter)
info_handler.setLevel(logging.DEBUG)
log.addHandler(info_handler)

error_handler = RotatingFileHandler(
    LOG_ERROR_FILE_NAME, mode="a", maxBytes=10 * 1024 * 1024, backupCount=5
)
error_handler.setFormatter(formatter)
error_handler.setLevel(logging.ERROR)
log.addHandler(error_handler)

stdoutAndstderr = logging.StreamHandler()
stdoutAndstderr.setLevel(logging.DEBUG)
stdoutAndstderr.setFormatter(formatter)
log.addHandler(stdoutAndstderr)

log.setLevel(logging.DEBUG)
Reply
#2
Thank you Larz60+. Will keep in mind.
Reply
#3
Any help is highly appreciated guys...
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020