MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / fileConfig

Function fileConfig

tools/python-3.11.9-amd64/Lib/logging/config.py:52–93  ·  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 ch

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

Source from the content-addressed store, hash-verified

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

Callers 1

handleMethod · 0.85

Calls 8

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

Tested by

no test coverage detected