parameters: (self, message, severity, mode=LogMode.EACH, stack_depth=2, error_ok=False)
docstring: Logs a message to stdout.
  
          Args:
              message (Union[str, Callable() -> str]):
                      A string or callable which returns a string of the message to log.
              severity (Logger.Severity):
                      The severity with which to log this message. If the severity is less than
                      the logger's current severity, the message is suppressed. Provided callables
                      will not be called in that case.
              mode (LogMode):
                      Controls how the message is logged.
                      See LogMode for details.
              stack_depth (int):
                      The stack depth to use to determine file and line information.
                      Defaults to 2.
              error_ok (bool):
                      Whether to suppress errors encountered while logging.
                      When this is True, in the event of an error, the message will not be
                      logged, but the logger will recover and resume execution.
                      When False, the logger will re-raise the exception.
docstring_summary: Logs a message to stdout.
docstring_tokens: Logs a message to stdout .
function: def log(self, message, severity, mode=LogMode.EACH, stack_depth=2, error_ok=False):
          """
          Logs a message to stdout.
  
          Args:
              message (Union[str, Callable() -> str]):
                      A string or callable which returns a string of the message to log.
              severity (Logger.Severity):
                      The severity with which to log this message. If the severity is less than
                      the logger's current severity, the message is suppressed. Provided callables
                      will not be called in that case.
              mode (LogMode):
                      Controls how the message is logged.
                      See LogMode for details.
              stack_depth (int):
                      The stack depth to use to determine file and line information.
                      Defaults to 2.
              error_ok (bool):
                      Whether to suppress errors encountered while logging.
                      When this is True, in the event of an error, the message will not be
                      logged, but the logger will recover and resume execution.
                      When False, the logger will re-raise the exception.
          """
          from polygraphy import constants, config
  
          def process_message(message, stack_depth):
              def get_prefix():
                  def get_line_info():
                      adjusted_stack_depth = stack_depth
                      adjusted_stack_depth += 2
                      module = inspect.getmodule(sys._getframe(adjusted_stack_depth))
                      # Handle logging from the top-level of a module.
                      if not module:
                          adjusted_stack_depth -= 1
                          module = inspect.getmodule(sys._getframe(adjusted_stack_depth))
                      filename = module.__file__
                      filename = os.path.relpath(filename, self.root_dir)
                      # If the file is not located in polygraphy, use its basename instead.
                      if os.pardir in filename:
                          filename = os.path.basename(filename)
                      return "[{:}:{:}] ".format(filename, sys._getframe(adjusted_stack_depth).f_lineno)
  
                  prefix = ""
                  if self.letter:
                      prefix += Logger.SEVERITY_LETTER_MAPPING[severity] + " "
                  if self.timestamp:
                      prefix += "({:}) ".format(time.strftime("%X"))
                  if self.line_info:
                      prefix += get_line_info()
                  return prefix
  
              def apply_indentation(prefix, message):
                  message_lines = str(message).splitlines()
                  tab = constants.TAB * self.logging_indent
                  newline_tab = "\n" + tab + " " * len(prefix)
                  return tab + newline_tab.join([line for line in message_lines])
  
              def apply_color(message):
                  if self.colors and has_colors():
                      import colored
  
                      color = Logger.SEVERITY_COLOR_MAPPING[severity]
                      return colored.stylize(message, [colored.fg(color)]) if color else message
                  return message
  
              prefix = get_prefix()
              message = apply_indentation(prefix, message)
              return apply_color("{:}{:}".format(prefix, message))
  
          def should_log(message):
              should = severity >= self._severity
              if should and mode == LogMode.ONCE:
                  message_hash = hash(message)
                  should &= message_hash not in self.once_logged
                  self.once_logged.add(message_hash)
              return should
  
          if not should_log(message):
              return
  
          if callable(message):
              try:
                  message = message()
              except Exception as err:
                  if not error_ok or config.INTERNAL_CORRECTNESS_CHECKS:
                      raise
                  message = "<Error while logging this message: {:}>".format(str(err))
  
          message = str(message)
          message = message.replace("\t", constants.TAB)
  
          # Use the warnings module in correctness checking mode so all warnings are
          # visible in the test result summary.
          if config.INTERNAL_CORRECTNESS_CHECKS and severity == Logger.WARNING:
              import warnings
  
              warnings.warn(message)
  
          message = process_message(message, stack_depth=stack_depth)
  
          if self._log_file is not None:
              self._log_file.write(message + "\n")
              self._log_file.flush()
  
          print(message, file=sys.stdout if severity < Logger.CRITICAL else sys.stderr)
function_tokens: def log ( self , message , severity , mode = LogMode . EACH , stack_depth = 2 , error_ok = False ) : from polygraphy import constants , config def process_message ( message , stack_depth ) : def get_prefix ( ) : def get_line_info ( ) : adjusted_stack_depth = stack_depth adjusted_stack_depth += 2 module = inspect . getmodule ( sys . _getframe ( adjusted_stack_depth ) ) # Handle logging from the top-level of a module. if not module : adjusted_stack_depth -= 1 module = inspect . getmodule ( sys . _getframe ( adjusted_stack_depth ) ) filename = module . __file__ filename = os . path . relpath ( filename , self . root_dir ) # If the file is not located in polygraphy, use its basename instead. if os . pardir in filename : filename = os . path . basename ( filename ) return "[{:}:{:}] " . format ( filename , sys . _getframe ( adjusted_stack_depth ) . f_lineno ) prefix = "" if self . letter : prefix += Logger . SEVERITY_LETTER_MAPPING [ severity ] + " " if self . timestamp : prefix += "({:}) " . format ( time . strftime ( "%X" ) ) if self . line_info : prefix += get_line_info ( ) return prefix def apply_indentation ( prefix , message ) : message_lines = str ( message ) . splitlines ( ) tab = constants . TAB * self . logging_indent newline_tab = "\n" + tab + " " * len ( prefix ) return tab + newline_tab . join ( [ line for line in message_lines ] ) def apply_color ( message ) : if self . colors and has_colors ( ) : import colored color = Logger . SEVERITY_COLOR_MAPPING [ severity ] return colored . stylize ( message , [ colored . fg ( color ) ] ) if color else message return message prefix = get_prefix ( ) message = apply_indentation ( prefix , message ) return apply_color ( "{:}{:}" . format ( prefix , message ) ) def should_log ( message ) : should = severity >= self . _severity if should and mode == LogMode . ONCE : message_hash = hash ( message ) should &= message_hash not in self . once_logged self . once_logged . add ( message_hash ) return should if not should_log ( message ) : return if callable ( message ) : try : message = message ( ) except Exception as err : if not error_ok or config . INTERNAL_CORRECTNESS_CHECKS : raise message = "<Error while logging this message: {:}>" . format ( str ( err ) ) message = str ( message ) message = message . replace ( "\t" , constants . TAB ) # Use the warnings module in correctness checking mode so all warnings are # visible in the test result summary. if config . INTERNAL_CORRECTNESS_CHECKS and severity == Logger . WARNING : import warnings warnings . warn ( message ) message = process_message ( message , stack_depth = stack_depth ) if self . _log_file is not None : self . _log_file . write ( message + "\n" ) self . _log_file . flush ( ) print ( message , file = sys . stdout if severity < Logger . CRITICAL else sys . stderr )