Python Forum

Full Version: How to rotate log and limit the size
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

Below is my logging function and it is defined in my class. There are multiple functions are defined in my class and also a different file which is being imported as well. Here I need to limit the file size as well as once it reaches the limit it should start write into a another file name (logging_1.log) or so.
import logging
import myfile

class MyClass(object):
    def __init__(self, myparams):
        '''
        '''
        self.action = 'write'
        self.__logging_function()
        logging.info('printing logging information')
        self.__my_function()
    
    def __logging_function(self):
        '''
        '''
        logging_file   = 'logging.log'
        logging_format = '%(asctime)s: [%(levelname)s] [{}] %(message)s'.format(self.action)                      
        logging.basicConfig(
            filename = '{}'.format(logging_file),
            format   = '{}'.format(logging_format),
            level    = logging.DEBUG
        )

    def __my_function(self):
        '''
        '''
        logging.debug('printing information for debugging purpose')
Could any one help me out to achieve this. Much appreciated. Thank you.

Regards,
Maiya