I am working in a big python module(Python 2.6.6) and doing logging in thousand of places and i am using logger module of python. Now, i want to ignore the exception, which are generated during the logging. One of the basic scenario which could be possible is
import glob
import logging
import logging.handlers
LOG_FILENAME = '/home/abc/logging_rotatingfile_example.out'
my_logger = logging.getLogger('MyLogger')
my_logger.setLevel(logging.DEBUG)
# Add the log message handler to the logger
handler = logging.handlers.RotatingFileHandler(
LOG_FILENAME, maxBytes=20, backupCount=5)
my_logger.addHandler(handler)
# Log some messages
for i in range(20):
my_logger.debug('i = %d' % i)
Now suppose, during the my_logger.debug('i = %d' % i)
some how the file is deleted from the system or permissions are changed and logger couldn't able to log due to disk failure, disk full etc. on the log file and generate the exception on the screen.
It is distributed system and n number of process are using logger module. Please note process should not be aborted due to logging exception(due to disk failure, disk full etc.).
So i want that exception to be ignored.
NOTE: Now one of the way i know to make wrapper class on python logger and use try-except for the logger function. But i have different requirements and i dont want to use that way so ,is there any other way to do this or any attribute of python logger which can be useful for my condition?
try
-except
? – Cyclonite