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 iteration log operation based on Ignite `engine.state.output` data.
  Print the values from `self.output_transform(engine.state.output)`.
  Since `engine.state.output` is a decollated list and we replicated the loss value for every item
  of the decollated list, the default behavior is to print the loss from `output[0]`.
  
  Args:
      engine: Ignite Engine, it can be a trainer, validator or evaluator.
docstr_tok: ["Execute","iteration","log","operation","based","on","Ignite","`","engine.state.output","`","data",".","Print","the","values","from","`","self.output_transform","(","engine.state.output",")","`",".","Since","`","engine.state.output","`","is","a","decollated","list","and","we","replicated","the","loss","value","for","every","item","of","the","decollated","list",",","the","default","behavior","is","to","print","the","loss","from","`","output","[","0","]","`",".","Args",":","engine",":","Ignite","Engine",",","it","can","be","a","trainer",",","validator","or","evaluator","."]
code: def _default_iteration_print(self, engine: Engine) -> None:
      """
      Execute iteration log operation based on Ignite `engine.state.output` data.
      Print the values from `self.output_transform(engine.state.output)`.
      Since `engine.state.output` is a decollated list and we replicated the loss value for every item
      of the decollated list, the default behavior is to print the loss from `output[0]`.
  
      Args:
          engine: Ignite Engine, it can be a trainer, validator or evaluator.
  
      """
      loss = self.output_transform(engine.state.output)
      if loss is None:
          return  # no printing if the output is empty
  
      out_str = ""
      if isinstance(loss, dict):  # print dictionary items
          for name in sorted(loss):
              value = loss[name]
              if not is_scalar(value):
                  warnings.warn(
                      "ignoring non-scalar output in StatsHandler,"
                      " make sure `output_transform(engine.state.output)` returns"
                      " a scalar or dictionary of key and scalar pairs to avoid this warning."
                      " {}:{}".format(name, type(value))
                  )
                  continue  # not printing multi dimensional output
              out_str += self.key_var_format.format(
                  name,
                  value.item()
                  if isinstance(value, torch.Tensor)
                  else value,
              )
      elif is_scalar(loss):  # not printing multi dimensional output
          out_str += self.key_var_format.format(
              self.tag_name,
              loss.item() if isinstance(loss, torch.Tensor) else loss,
          )
      else:
          warnings.warn(
              "ignoring non-scalar output in StatsHandler,"
              " make sure `output_transform(engine.state.output)` returns"
              " a scalar or a dictionary of key and scalar pairs to avoid this warning."
              " {}".format(type(loss))
          )
  
      if not out_str:
          return  # no value to print
  
      num_iterations = engine.state.epoch_length
      current_iteration = engine.state.iteration
      if num_iterations is not None:
          current_iteration = (
              current_iteration - 1
          ) % num_iterations + 1
      current_epoch = engine.state.epoch
      num_epochs = engine.state.max_epochs
  
      base_str = f"Epoch: {current_epoch}/{num_epochs}, Iter: {current_iteration}/{num_iterations} --"
  
      self.logger.info(" ".join([base_str, 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 7 for calling the StatsHandler obj's underlying member method code with example usage: obj._default_iteration_print(engine) without return types