MCPcopy Index your code
hub / github.com/RustPython/RustPython / __init__

Method __init__

Lib/logging/__init__.py:298–385  ·  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

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

Callers

nothing calls this directly

Calls 8

lenFunction · 0.85
isinstanceFunction · 0.85
getLevelNameFunction · 0.85
hasattrFunction · 0.85
basenameMethod · 0.80
splitextMethod · 0.80
getMethod · 0.45
get_nameMethod · 0.45

Tested by

no test coverage detected