Python Forum
How to rotate log and limit the size
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to rotate log and limit the size
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter Entry size limit vman44 3 6,745 Dec-22-2022, 06:58 AM
Last Post: vman44
  How to rotate bits ? korenron 2 1,637 Mar-23-2022, 04:05 PM
Last Post: Larz60+
  Rotate 2D Gaussian given parameters schniefen 4 2,920 Dec-11-2020, 03:34 PM
Last Post: schniefen
  How to limit the fie size in logging. maiya 2 7,300 Jul-29-2020, 06:49 AM
Last Post: maiya
  size of set vs size of dict zweb 0 2,148 Oct-11-2019, 01:32 AM
Last Post: zweb
  Restrict / Limit variable size mln4python 4 7,178 Aug-13-2019, 07:17 AM
Last Post: mln4python
  CSV file created is huge in size. How to reduce the size? pramoddsrb 0 10,488 Apr-26-2018, 12:38 AM
Last Post: pramoddsrb

Forum Jump:

User Panel Messages

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