Continuously read and copy log file1/12/2023 This procedure requires the whole file where the child process is created to be reloaded from scratch. Indeed, this operating system does not support forking, so Python has to use an alternative method to create sub-processes called “spawning”. Things get a little more complicated on Windows. add ( "file.log", enqueue = True ) process = multiprocessing. complete () if _name_ = "_main_" : logger. info ( "Executing function in child process" ) logger. # Linux implementation import multiprocessing from loguru import logger def my_process (): logger. If you add a handler to a deep copied logger, it will not be shared with others functions using the original logger: In such case, it is recommended to rely on the epcopy() built-in method that will create an independent logger object. Most importantly, it may unnecessarily slow down your application as each log will need to be checked by the filter function of each handler. It may be a bit cumbersome to configure every handlers like this. Now, supposing that you have a lot of these tasks. That way, "file_A.log" and "file_B.log" will only contains logs from respectively the task_A() and task_B() function. add ( "file_B.log", filter = lambda record : record = "B" ) task_A () task_B () add ( "file_A.log", filter = lambda record : record = "A" ) logger. info ( "Starting task B" ) do_something_else () logger_b. success ( "End of task A" ) def task_B (): logger_b = logger. info ( "Starting task A" ) do_something () logger_a. All additional **kwargs argument are passed to the built-in open() function.įor other types of handlers, you have to check if there is a way to parametrize encoding or fallback policy.įrom loguru import logger def task_A (): logger_a = logger. If you are using a file sink, you can configure the errors or encoding parameter while adding the handler like logger.add("file.log", encoding="utf8") for example.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |