class_docstr: 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
class_docstr_tok: ["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","does","n'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","does","n't","exist"]
code: def attach(self, engine: Engine) -> None:
      self.logger = engine.logger
      engine.add_event_handler(Events.STARTED, self._start)
      engine.add_event_handler(Events.COMPLETED, self._completed)
  
file_path: MONAI/monai/handlers/logfile_handler.py
imports: from __future__ import annotations
  import logging
  import os
  from typing import TYPE_CHECKING
  from monai.config import IgniteInfo
  from monai.utils import min_version, optional_import
label_desc: Use image node_id 2 for calling the LogfileHandler obj's underlying member method code with example usage: obj.attach(engine) without return types