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: Args:
      iteration_log: whether to log data when iteration completed, default to `True`. ``iteration_log`` can
          be also a function and it will be interpreted as an event filter
          (see https://pytorch.org/ignite/generated/ignite.engine.events.Events.html for details).
          Event filter function accepts as input engine and event value (iteration) and should return True/False.
          Event filtering can be helpful to customize iteration logging frequency.
      epoch_log: whether to log data when epoch completed, default to `True`. ``epoch_log`` can be
          also a function and it will be interpreted as an event filter. See ``iteration_log`` argument for more
          details.
      epoch_print_logger: customized callable printer for epoch level logging.
          Must accept parameter "engine", use default printer if None.
      iteration_print_logger: customized callable printer for iteration level logging.
          Must accept parameter "engine", use default printer if None.
      output_transform: a callable that is used to transform the
          ``ignite.engine.state.output`` into a scalar to print, or a dictionary of {key: scalar}.
          In the latter case, the output string will be formatted as key: value.
          By default this value logging happens when every iteration completed.
          The default behavior is to print loss from output[0] as output is a decollated list
          and we replicated loss value for every item of the decollated list.
          `engine.state` and `output_transform` inherit from the ignite concept:
          https://pytorch.org/ignite/concepts.html#state, explanation and usage example are in the tutorial:
          https://github.com/Project-MONAI/tutorials/blob/master/modules/batch_output_transform.ipynb.
      global_epoch_transform: a callable that is used to customize global epoch number.
          For example, in evaluation, the evaluator engine might want to print synced epoch number
          with the trainer engine.
      state_attributes: expected attributes from `engine.state`, if provided, will extract them
          when epoch completed.
      name: identifier of `logging.logger` to use, if None, defaulting to ``engine.logger``.
      tag_name: when iteration output is a scalar, tag_name is used to print
          tag_name: scalar_value to logger. Defaults to ``'Loss'``.
      key_var_format: a formatting string to control the output string format of key: value.
docstr_tok: ["Args",":","iteration_log",":","whether","to","log","data","when","iteration","completed",",","default","to","`","True","`",".","``","iteration_log","``","can","be","also","a","function","and","it","will","be","interpreted","as","an","event","filter","(","see","https",":","\/\/pytorch.org\/ignite\/generated\/ignite.engine.events.Events.html","for","details",")",".","Event","filter","function","accepts","as","input","engine","and","event","value","(","iteration",")","and","should","return","True\/False",".","Event","filtering","can","be","helpful","to","customize","iteration","logging","frequency",".","epoch_log",":","whether","to","log","data","when","epoch","completed",",","default","to","`","True","`",".","``","epoch_log","``","can","be","also","a","function","and","it","will","be","interpreted","as","an","event","filter",".","See","``","iteration_log","``","argument","for","more","details",".","epoch_print_logger",":","customized","callable","printer","for","epoch","level","logging",".","Must","accept","parameter","``","engine","''",",","use","default","printer","if","None",".","iteration_print_logger",":","customized","callable","printer","for","iteration","level","logging",".","Must","accept","parameter","``","engine","''",",","use","default","printer","if","None",".","output_transform",":","a","callable","that","is","used","to","transform","the","``","ignite.engine.state.output","``","into","a","scalar","to","print",",","or","a","dictionary","of","{","key",":","scalar","}",".","In","the","latter","case",",","the","output","string","will","be","formatted","as","key",":","value",".","By","default","this","value","logging","happens","when","every","iteration","completed",".","The","default","behavior","is","to","print","loss","from","output","[","0","]","as","output","is","a","decollated","list","and","we","replicated","loss","value","for","every","item","of","the","decollated","list",".","`","engine.state","`","and","`","output_transform","`","inherit","from","the","ignite","concept",":","https",":","\/\/pytorch.org\/ignite\/concepts.html","#","state",",","explanation","and","usage","example","are","in","the","tutorial",":","https",":","\/\/github.com\/Project-MONAI\/tutorials\/blob\/master\/modules\/batch_output_transform.ipynb",".","global_epoch_transform",":","a","callable","that","is","used","to","customize","global","epoch","number",".","For","example",",","in","evaluation",",","the","evaluator","engine","might","want","to","print","synced","epoch","number","with","the","trainer","engine",".","state_attributes",":","expected","attributes","from","`","engine.state","`",",","if","provided",",","will","extract","them","when","epoch","completed",".","name",":","identifier","of","`","logging.logger","`","to","use",",","if","None",",","defaulting","to","``","engine.logger","``",".","tag_name",":","when","iteration","output","is","a","scalar",",","tag_name","is","used","to","print","tag_name",":","scalar_value","to","logger",".","Defaults","to","``","'Loss","'","``",".","key_var_format",":","a","formatting","string","to","control","the","output","string","format","of","key",":","value","."]
code: def __init__(
      self,
      iteration_log: bool | Callable[[Engine, int], bool] = True,
      epoch_log: bool | Callable[[Engine, int], bool] = True,
      epoch_print_logger: Callable[[Engine], Any] | None = None,
      iteration_print_logger: Callable[[Engine], Any] | None = None,
      output_transform: Callable = lambda x: x[0],
      global_epoch_transform: Callable = lambda x: x,
      state_attributes: Sequence[str] | None = None,
      name: str | None = "StatsHandler",
      tag_name: str = DEFAULT_TAG,
      key_var_format: str = DEFAULT_KEY_VAL_FORMAT,
  ) -> None:
      """
  
      Args:
          iteration_log: whether to log data when iteration completed, default to `True`. ``iteration_log`` can
              be also a function and it will be interpreted as an event filter
              (see https://pytorch.org/ignite/generated/ignite.engine.events.Events.html for details).
              Event filter function accepts as input engine and event value (iteration) and should return True/False.
              Event filtering can be helpful to customize iteration logging frequency.
          epoch_log: whether to log data when epoch completed, default to `True`. ``epoch_log`` can be
              also a function and it will be interpreted as an event filter. See ``iteration_log`` argument for more
              details.
          epoch_print_logger: customized callable printer for epoch level logging.
              Must accept parameter "engine", use default printer if None.
          iteration_print_logger: customized callable printer for iteration level logging.
              Must accept parameter "engine", use default printer if None.
          output_transform: a callable that is used to transform the
              ``ignite.engine.state.output`` into a scalar to print, or a dictionary of {key: scalar}.
              In the latter case, the output string will be formatted as key: value.
              By default this value logging happens when every iteration completed.
              The default behavior is to print loss from output[0] as output is a decollated list
              and we replicated loss value for every item of the decollated list.
              `engine.state` and `output_transform` inherit from the ignite concept:
              https://pytorch.org/ignite/concepts.html#state, explanation and usage example are in the tutorial:
              https://github.com/Project-MONAI/tutorials/blob/master/modules/batch_output_transform.ipynb.
          global_epoch_transform: a callable that is used to customize global epoch number.
              For example, in evaluation, the evaluator engine might want to print synced epoch number
              with the trainer engine.
          state_attributes: expected attributes from `engine.state`, if provided, will extract them
              when epoch completed.
          name: identifier of `logging.logger` to use, if None, defaulting to ``engine.logger``.
          tag_name: when iteration output is a scalar, tag_name is used to print
              tag_name: scalar_value to logger. Defaults to ``'Loss'``.
          key_var_format: a formatting string to control the output string format of key: value.
  
      """
  
      self.iteration_log = iteration_log
      self.epoch_log = epoch_log
      self.epoch_print_logger = epoch_print_logger
      self.iteration_print_logger = iteration_print_logger
      self.output_transform = output_transform
      self.global_epoch_transform = global_epoch_transform
      self.state_attributes = state_attributes
      self.tag_name = tag_name
      self.key_var_format = key_var_format
      self.logger = get_logger(name)  # type: ignore
      self.name = name
  
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 1 to create a new StatsHandler object  with example: obj = StatsHandler(iteration_log, epoch_log, epoch_print_logger, iteration_print_logger, output_transform, global_epoch_transform, state_attributes, name, tag_name, key_var_format)