def _rotate(self, filename, last, trigger):
        if not os.path.exists(filename):
            return

        suffix = ''
        if self.compress == 'gz':
            suffix = '.'+self.compress

        roll_first = filename+'.1'+suffix
        renames = [(filename, roll_first)]
        self.logger.info('Rotating logfile %s to %s' % (filename, roll_first))
        for n, (oldname, newname) in enumerate(renames):
            if self.max_count and n == self.max_count-1:
                # cap renamed files if max_count specified
                break

            if os.path.exists(newname):
                base, num = newname.strip(suffix).rsplit('.', 1)
                renames.append((newname, '%s.%s%s' % (base, int(num)+1, suffix)))

        if suffix:
            # actually a rename, then compress
            renames[0] = (filename, filename+'.1')

        for oldname, newname in reversed(renames):
            self.logger.debug('Renaming logfile %s->%s' % (oldname, newname))
            os.rename(oldname, newname)

        if self.compress == 'gz':
            self._gz(filename+'.1')

        # emit 'virtual' event for rolled log file
        self.output.put(Event(tags=['fileroll'], filename=roll_first, last=last or trigger, trigger=trigger))
dataset/ETHPy150Open artirix/logcabin/logcabin/outputs/file.py/File._rotate/original