SPPAS 4.22

https://sppas.org/

Module sppas.config

Class sppasLogFile

Description

Manager for logs of SPPAS runs.

Constructor

Create a sppasLogFile instance.

Create the log directory if it not already exists then fix the log filename with increment=0.

Parameters
  • pattern
View Source
def __init__(self, pattern='log'):
    """Create a sppasLogFile instance.

    Create the log directory if it not already exists then fix the
    log filename with increment=0.

    """
    log_dir = paths.logs
    if os.path.exists(log_dir) is False:
        os.mkdir(log_dir)
    self.__filename = '{:s}_{:s}_'.format(sg.__name__, pattern)
    self.__filename += str(date.today()) + '_'
    self.__filename += str(os.getpid()) + '_'
    self.__current = 1
    while os.path.exists(self.get_filename()) is True:
        self.__current += 1

Public functions

get_filename

Return the current log filename.

View Source
def get_filename(self):
    """Return the current log filename."""
    fn = os.path.join(paths.logs, self.__filename)
    fn += '{0:04d}'.format(self.__current)
    return fn + '.txt'

increment

Increment the current log filename.

View Source
def increment(self):
    """Increment the current log filename."""
    self.__current += 1

get_header

Return a string with an header for logs.

View Source
@staticmethod
def get_header():
    """Return a string with an header for logs."""
    header = '-' * 78
    header += '\n\n'
    header += ' {:s} {:s}'.format(sg.__name__, sg.__version__)
    header += '\n'
    header += ' {:s}'.format(datetime.now().strftime('%Y/%m/%d %H:%M:%S'))
    header += '\n'
    header += ' {:s}'.format(platform.platform())
    header += '\n'
    header += ' {:s}'.format(sys.executable)
    header += '\n'
    header += ' python {:s}'.format(platform.python_version())
    if IMPORT_WX:
        header += '\n'
        header += ' wxpython {:s}'.format(wx.version())
    header += '\n\n'
    header += '-' * 78
    header += '\n\n'
    return header