Ejemplo n.º 1
0
 def __repr__(self):
     level = get_level_name(self.level)
     return f"<${self.__class__.__name__} (${level})>"
Ejemplo n.º 2
0
 def test_it_returns_the_proper_textual_representation_of_the_name(self):
     self.assertEqual(get_level_name(20), "INFO")
     self.assertEqual(get_level_name(LogLevel.INFO), "INFO")
Ejemplo n.º 3
0
 def __init__(self,
              name: str,
              level: LogLevel,
              pathname: str,
              lineno: int,
              msg,
              args=None,
              exc_info=None,
              func=None,
              sinfo=None,
              **kwargs) -> None:
     """
     :param name: The name of the logger used to log the event represented
     by this LogRecord. Note that this name will always have this value,
     even though it may be emitted by a handler attached to a
     different (ancestor) logger.
     :param level: The numeric level of the logging event (one of DEBUG,
     INFO etc.) Note that this is converted to two attributes of the
     LogRecord: levelno for the numeric value and levelname for the
     corresponding level name.
     :param pathname: The full pathname of the source file where the
     logging call was made.
     :param lineno: The line number in the source file where the logging
     call was made.
     :param msg: The event description message, possibly a format string
     with placeholders for variable data.
     :param args: Variable data to merge into the msg argument to obtain
     the event description.
     :param exc_info: An exception tuple with the current exception
     information, or None if no exception information is available.
     :param func: The name of the function or method from which the
     logging call was invoked.
     :param sinfo: A text string representing stack information from the
     base of the stack in the current thread, up to the logging call.
     """
     created_at = time.time()
     self.name = name
     self.msg = msg
     if args:
         if len(args) != 1 or not isinstance(args[0], Mapping):
             raise ValueError("Invalid LogRecord args type: {}. "
                              "Expected Mapping".format(type(args[0])))
         self.args = args[0]
     else:
         self.args = args
     self.levelname = get_level_name(level)
     self.levelno = level
     self.pathname = pathname
     try:
         self.filename = os.path.basename(pathname)
         self.module = os.path.splitext(self.filename)[0]
     except (TypeError, ValueError, AttributeError):
         self.filename = pathname
         self.module = "Unknown module"
     self.exc_info = exc_info
     self.exc_text = None  # used to cache the traceback text
     self.stack_info = sinfo
     self.lineno = lineno
     self.funcName = func
     self.created = created_at
     self.msecs = (created_at - int(created_at)) * 1000
     self.process = os.getpid()
     self.asctime = None
     self.message = None
Ejemplo n.º 4
0
 def test_it_raises_an_error_if_level_is_invalid(self):
     with self.assertRaises(ValueError):
         get_level_name(666)
Ejemplo n.º 5
0
 def __repr__(self):
     level = get_level_name(self.level)
     return "<${} (${})>".format(
         self.__class__.__name__,
         level
     )