loguru icon indicating copy to clipboard operation
loguru copied to clipboard

No new file generated while rotating

Open WuMenghao opened this issue 3 years ago • 4 comments

There are problems when i use loguru in my project. I don't know how it arise. I set rotation to "00:00" , but sometime, on my server, no new file generated while rotating, but the old log file was compressed and successfully generated. Next days ,there was still no no new file generated . I was confused , because i can not replay on my own machine.

class LOG(object):

    @classmethod
    def get_logger(cls, file_name , enqueue=False ):
        self = object.__new__(cls)
        self.__init__(file_name,enqueue=enqueue)
        return self.logger

    def __init__(self, file_name, is_multiprocess_handler = False, format=LOGURU_FORMAT, level=INFO,
                 rotation="00:00", retention="3 days", compression="zip",
                 enqueue=False):
        self.logger = loguru.logger

        self.file_path = f'log/{file_name}.log'

        self.file_error_path = f'log/{file_name}-error.log'
        if not os.path.exists("./log"):
            os.makedirs("./log/")
        self.logger.add(self.file_path, format=format, level=level, enqueue=enqueue, rotation=rotation,
                        retention=retention,
                        compression=compression)

        self.logger.add(self.file_error_path, format=LOGURU_FORMAT, level=ERROR, enqueue=enqueue,
                        rotation=rotation,
                        retention="30 days",
                        compression=compression)
logger = logger_util.LOG.get_logger("cti_download_task_by_day", enqueue=True)

The os version of my server:

Linux version 4.19.0-16-amd64 ([email protected]) (gcc version 8.3.0 (Debian 8.3.0-6)) #1 SMP Debian 4.19.181-1 (2021-03-19)

WuMenghao avatar Mar 02 '22 07:03 WuMenghao

So your app was still running but logs were not written to the file, right? Is there any chance you can look at the stderr at the time of the rotation? Maybe some Exception is raised.

Delgan avatar Mar 02 '22 07:03 Delgan

No , the stderr is redirected to /dev/null . I only need the log files so . You mean that there might be some Exception raised during a rotation.

WuMenghao avatar Mar 02 '22 08:03 WuMenghao

Yes, Loguru tries to capture unexpected exception occurring while logging and display them on stderr. You may find it useful if you save it somewhere.

Still, Loguru is not supposed to close the handler if there is an error. It usually just retry later when next message is logged. So, the behavior you're facing is unexpected. It might be a bug, or that the file handler is still valid despite not existing, or that thread is blocked for some unknown reason.

Delgan avatar Mar 02 '22 18:03 Delgan

Thanks, May be I neet find out More details first.

WuMenghao avatar Mar 04 '22 08:03 WuMenghao