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

Function fileConfig

Lib/logging/config.py:53–91  ·  view source on GitHub ↗

Read the logging configuration from a ConfigParser-format file. This can be called several times from an application, allowing an end user the ability to select from various pre-canned configurations (if the developer provides a mechanism to present the choices and load the chosen

(fname, defaults=None, disable_existing_loggers=True, encoding=None)

Source from the content-addressed store, hash-verified

51_listener = None
52
53def fileConfig(fname, defaults=None, disable_existing_loggers=True, encoding=None):
54 """
55 Read the logging configuration from a ConfigParser-format file.
56
57 This can be called several times from an application, allowing an end user
58 the ability to select from various pre-canned configurations (if the
59 developer provides a mechanism to present the choices and load the chosen
60 configuration).
61 """
62 import configparser
63
64 if isinstance(fname, str):
65 if not os.path.exists(fname):
66 raise FileNotFoundError(f"{fname} doesn't exist")
67 elif not os.path.getsize(fname):
68 raise RuntimeError(f'{fname} is an empty file')
69
70 if isinstance(fname, configparser.RawConfigParser):
71 cp = fname
72 else:
73 try:
74 cp = configparser.ConfigParser(defaults)
75 if hasattr(fname, 'readline'):
76 cp.read_file(fname)
77 else:
78 encoding = io.text_encoding(encoding)
79 cp.read(fname, encoding=encoding)
80 except configparser.ParsingError as e:
81 raise RuntimeError(f'{fname} is invalid: {e}')
82
83 formatters = _create_formatters(cp)
84
85 # critical section
86 with logging._lock:
87 _clearExistingHandlers()
88
89 # Handlers add themselves to logging._handlers
90 handlers = _install_handlers(cp, formatters)
91 _install_loggers(cp, handlers, disable_existing_loggers)
92
93
94def _resolve(name):

Callers 1

handleMethod · 0.85

Calls 7

_create_formattersFunction · 0.85
_clearExistingHandlersFunction · 0.85
_install_handlersFunction · 0.85
_install_loggersFunction · 0.85
existsMethod · 0.45
read_fileMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…