MCPcopy Index your code
hub / github.com/python/cpython / __init__

Method __init__

Lib/logging/__init__.py:295–382  ·  view source on GitHub ↗

Initialize a logging record with interesting information.

(self, name, level, pathname, lineno,
                 msg, args, exc_info, func=None, sinfo=None, **kwargs)

Source from the content-addressed store, hash-verified

293 information to be logged.
294 """
295 def __init__(self, name, level, pathname, lineno,
296 msg, args, exc_info, func=None, sinfo=None, **kwargs):
297 """
298 Initialize a logging record with interesting information.
299 """
300 ct = time.time_ns()
301 self.name = name
302 self.msg = msg
303 #
304 # The following statement allows passing of a dictionary as a sole
305 # argument, so that you can do something like
306 # logging.debug("a %(a)d b %(b)s", {'a':1, 'b':2})
307 # Suggested by Stefan Behnel.
308 # Note that without the test for args[0], we get a problem because
309 # during formatting, we test to see if the arg is present using
310 # 'if self.args:'. If the event being logged is e.g. 'Value is %d'
311 # and if the passed arg fails 'if self.args:' then no formatting
312 # is done. For example, logger.warning('Value is %d', 0) would log
313 # 'Value is %d' instead of 'Value is 0'.
314 # For the use case of passing a dictionary, this should not be a
315 # problem.
316 # Issue #21172: a request was made to relax the isinstance check
317 # to hasattr(args[0], '__getitem__'). However, the docs on string
318 # formatting still seem to suggest a mapping object is required.
319 # Thus, while not removing the isinstance check, it does now look
320 # for collections.abc.Mapping rather than, as before, dict.
321 if (args and len(args) == 1 and isinstance(args[0], collections.abc.Mapping)
322 and args[0]):
323 args = args[0]
324 self.args = args
325 self.levelname = getLevelName(level)
326 self.levelno = level
327 self.pathname = pathname
328 try:
329 self.filename = os.path.basename(pathname)
330 self.module = os.path.splitext(self.filename)[0]
331 except (TypeError, ValueError, AttributeError):
332 self.filename = pathname
333 self.module = "Unknown module"
334 self.exc_info = exc_info
335 self.exc_text = None # used to cache the traceback text
336 self.stack_info = sinfo
337 self.lineno = lineno
338 self.funcName = func
339 self.created = ct / 1e9 # ns to float seconds
340 # Get the number of whole milliseconds (0-999) in the fractional part of seconds.
341 # Eg: 1_677_903_920_999_998_503 ns --> 999_998_503 ns--> 999 ms
342 # Convert to float by adding 0.0 for historical reasons. See gh-89047
343 self.msecs = (ct % 1_000_000_000) // 1_000_000 + 0.0
344 if self.msecs == 999.0 and int(self.created) != ct // 1_000_000_000:
345 # ns -> sec conversion can round up, e.g:
346 # 1_677_903_920_999_999_900 ns --> 1_677_903_921.0 sec
347 self.msecs = 0.0
348
349 self.relativeCreated = (ct - _startTime) / 1e6
350 if logThreads:
351 self.thread = threading.get_ident()
352 self.threadName = threading.current_thread().name

Callers

nothing calls this directly

Calls 5

getLevelNameFunction · 0.85
splitextMethod · 0.80
basenameMethod · 0.45
getMethod · 0.45
get_nameMethod · 0.45

Tested by

no test coverage detected