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: Execute epoch level log operation.
  Default to print the values from Ignite `engine.state.metrics` dict and
  print the values of specified attributes of `engine.state`.
  
  Args:
      engine: Ignite Engine, it can be a trainer, validator or evaluator.
docstr_tok: ["Execute","epoch","level","log","operation",".","Default","to","print","the","values","from","Ignite","`","engine.state.metrics","`","dict","and","print","the","values","of","specified","attributes","of","`","engine.state","`",".","Args",":","engine",":","Ignite","Engine",",","it","can","be","a","trainer",",","validator","or","evaluator","."]
code: def _default_epoch_print(self, engine: Engine) -> None:
      """
      Execute epoch level log operation.
      Default to print the values from Ignite `engine.state.metrics` dict and
      print the values of specified attributes of `engine.state`.
  
      Args:
          engine: Ignite Engine, it can be a trainer, validator or evaluator.
  
      """
      current_epoch = self.global_epoch_transform(engine.state.epoch)
  
      prints_dict = engine.state.metrics
      if prints_dict is not None and len(prints_dict) > 0:
          out_str = f"Epoch[{current_epoch}] Metrics -- "
          for name in sorted(prints_dict):
              value = prints_dict[name]
              out_str += (
                  self.key_var_format.format(name, value)
                  if is_scalar(value)
                  else f"{name}: {str(value)}"
              )
          self.logger.info(out_str)
  
      if (
          hasattr(engine.state, "key_metric_name")
          and hasattr(engine.state, "best_metric")
          and hasattr(engine.state, "best_metric_epoch")
          and engine.state.key_metric_name is not None
      ):
          out_str = f"Key metric: {engine.state.key_metric_name} "
          out_str += f"best value: {engine.state.best_metric} "
          out_str += f"at epoch: {engine.state.best_metric_epoch}"
          self.logger.info(out_str)
  
      if (
          self.state_attributes is not None
          and len(self.state_attributes) > 0
      ):
          out_str = "State values: "
          for attr in self.state_attributes:
              out_str += f"{attr}: {getattr(engine.state, attr, None)} "
          self.logger.info(out_str)
  
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 6 for calling the StatsHandler obj's underlying member method code with example usage: obj._default_epoch_print(engine) without return types