class_docstr: StatsHandler defines a set of Ignite Event-handlers for all the log printing logics.
  It can be used for any Ignite Engine(trainer, validator and evaluator).
  And it can support logging for epoch level and iteration level with pre-defined loggers.
  
  Note that if ``name`` is None, this class will leverage `engine.logger` as the logger, otherwise,
  ``logging.getLogger(name)`` is used. In both cases, it's important to make sure that the logging level is at least
  ``INFO``. To change the level of logging, please call ``import ignite; ignite.utils.setup_logger(name)``
  (when ``name`` is not None) or ``engine.logger = ignite.utils.setup_logger(engine.logger.name, reset=True)``
  (when ``name`` is None) before running the engine with this handler attached.
  
  Default behaviors:
      - When EPOCH_COMPLETED, logs ``engine.state.metrics`` using ``self.logger``.
      - When ITERATION_COMPLETED, logs
        ``self.output_transform(engine.state.output)`` using ``self.logger``.
  
  Usage example::
  
      import ignite
      import monai
  
      trainer = ignite.engine.Engine(lambda x, y: [0.0])  # an example trainer
      monai.handlers.StatsHandler(name="train_stats").attach(trainer)
  
      trainer.run(range(3), max_epochs=4)
  
  More details of example is available in the tutorial:
  https://github.com/Project-MONAI/tutorials/blob/master/modules/engines/unet_training_dict.py.
class_docstr_tok: ["StatsHandler","defines","a","set","of","Ignite","Event-handlers","for","all","the","log","printing","logics",".","It","can","be","used","for","any","Ignite","Engine","(","trainer",",","validator","and","evaluator",")",".","And","it","can","support","logging","for","epoch","level","and","iteration","level","with","pre-defined","loggers",".","Note","that","if","``","name","``","is","None",",","this","class","will","leverage","`","engine.logger","`","as","the","logger",",","otherwise",",","``","logging.getLogger","(","name",")","``","is","used",".","In","both","cases",",","it","'s","important","to","make","sure","that","the","logging","level","is","at","least","``","INFO","``",".","To","change","the","level","of","logging",",","please","call","``","import","ignite",";","ignite.utils.setup_logger","(","name",")","``","(","when","``","name","``","is","not","None",")","or","``","engine.logger","=","ignite.utils.setup_logger","(","engine.logger.name",",","reset=True",")","``","(","when","``","name","``","is","None",")","before","running","the","engine","with","this","handler","attached",".","Default","behaviors",":","-","When","EPOCH_COMPLETED",",","logs","``","engine.state.metrics","``","using","``","self.logger","``",".","-","When","ITERATION_COMPLETED",",","logs","``","self.output_transform","(","engine.state.output",")","``","using","``","self.logger","``",".","Usage","example",":",":","import","ignite","import","monai","trainer","=","ignite.engine.Engine","(","lambda","x",",","y",":","[","0.0","]",")","#","an","example","trainer","monai.handlers.StatsHandler","(","name=","''","train_stats","''",")",".attach","(","trainer",")","trainer.run","(","range","(","3",")",",","max_epochs=4",")","More","details","of","example","is","available","in","the","tutorial",":","https",":","\/\/github.com\/Project-MONAI\/tutorials\/blob\/master\/modules\/engines\/unet_training_dict.py","."]
docstr: Register a set of Ignite Event-Handlers to a specified Ignite engine.
  
  Args:
      engine: Ignite Engine, it can be a trainer, validator or evaluator.
docstr_tok: ["Register","a","set","of","Ignite","Event-Handlers","to","a","specified","Ignite","engine",".","Args",":","engine",":","Ignite","Engine",",","it","can","be","a","trainer",",","validator","or","evaluator","."]
code: def attach(self, engine: Engine) -> None:
      """
      Register a set of Ignite Event-Handlers to a specified Ignite engine.
  
      Args:
          engine: Ignite Engine, it can be a trainer, validator or evaluator.
  
      """
      if self.name is None:
          self.logger = engine.logger
      if self.logger.getEffectiveLevel() > logging.INFO:
          suggested = f"\n\nimport ignite\nignite.utils.setup_logger('{self.logger.name}', reset=True)"
          if self.logger.name != engine.logger.name:
              suggested += f"\nignite.utils.setup_logger('{engine.logger.name}', reset=True)"
          suggested += "\n\n"
          warnings.warn(
              f"the effective log level of {self.logger.name} is higher than INFO, StatsHandler may not output logs,"
              f"\nplease use the following code before running the engine to enable it: {suggested}"
          )
      if self.iteration_log and not engine.has_event_handler(
          self.iteration_completed, Events.ITERATION_COMPLETED
      ):
          event = Events.ITERATION_COMPLETED
          if callable(
              self.iteration_log
          ):  # substitute event with new one using filter callable
              event = event(event_filter=self.iteration_log)
          engine.add_event_handler(event, self.iteration_completed)
      if self.epoch_log and not engine.has_event_handler(
          self.epoch_completed, Events.EPOCH_COMPLETED
      ):
          event = Events.EPOCH_COMPLETED
          if callable(
              self.epoch_log
          ):  # substitute event with new one using filter callable
              event = event(event_filter=self.epoch_log)
          engine.add_event_handler(event, self.epoch_completed)
      if not engine.has_event_handler(
          self.exception_raised, Events.EXCEPTION_RAISED
      ):
          engine.add_event_handler(
              Events.EXCEPTION_RAISED, self.exception_raised
          )
  
file_path: MONAI/monai/handlers/stats_handler.py
imports: from __future__ import annotations
  import logging
  import warnings
  from collections.abc import Callable, Sequence
  from typing import TYPE_CHECKING, Any
  import torch
  from monai.apps import get_logger
  from monai.config import IgniteInfo
  from monai.utils import is_scalar, min_version, optional_import
label_desc: Use image node_id 2 for calling the StatsHandler obj's underlying member method code with example usage: obj.attach(engine) without return types