U {Ph[@sddlmZddlZddlZddlmZddlmZddlm Z m Z e dej e d\Z Z erjddlmZne dej e d \ZZ d gZGd d d ZdS) ) annotationsN) TYPE_CHECKING) IgniteInfo) min_versionoptional_importz ignite.engineEvents)EnginerLogfileHandlerc@sbeZdZdZdejddfddddddd d Zd d d ddZd d d ddZd d d ddZ dS)r a Adds a `logging.FileHandler` to the attached engine's logger when the start event occurs and removes it again when then completed event occurs. A handler is needed to remove `FileHandler` object when the complete event occurs so that further runs of different engines write only to the log files they should, rather than previous files. Multiple handlers can write to the same file which allows output from train and evaluation engine objects to be condensed in one file. If the given output directory doesn't exist it will by default be created when the start event occurs. This can be used in conjunction with `CheckpointSaver` to save a log file to the same destination as the saved checkpoints. Since the handler is added possibly after other logging events during initialisation, not all logging data will be retained. Args: output_dir: directory to save the log file to filename: name of the file to save log to loglevel: log level for the handler formatter: format string for the `logging.Formatter` set for the handler create_dir: if True, create `output_dir` if it doesn't exist zlog.txtz/%(asctime)s %(name)s %(levelname)s: %(message)sTstrintbool) output_dirfilenameloglevel formatter create_dircCs.||_||_||_||_||_d|_d|_dSN)r rrrrloggerhandler)selfr rrrrrS/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/handlers/logfile_handler.py__init__2szLogfileHandler.__init__rNone)enginereturncCs,|j|_|tj|j|tj|jdSr)radd_event_handlerrSTARTED_start COMPLETED _completedrrrrrattachBszLogfileHandler.attachcCs|jr$tj|js$tj|jddttj|j|j |_ |j |j |j t|j|jdk rz|j|j ntddS)NT)exist_okz-`self.logger` must not be None in start event)rospathexistsr makedirslogging FileHandlerjoinrrsetLevelr setFormatter Formatterrr addHandlerAttributeErrorr!rrrrGs zLogfileHandler._startcCs@|jdk r.|jdk r.|j|j|jntdd|_dS)NzC`self.logger` and `self.handler` must not be None in complete event)rr removeHandlercloser/r!rrrr Ts  zLogfileHandler._completedN) __name__ __module__ __qualname____doc__r(INFOrr"rr rrrrr s ) __future__rr(r$typingr monai.configr monai.utilsrrOPT_IMPORT_VERSIONr_ ignite.enginer__all__r rrrr s