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

Function basicConfig

Lib/logging/__init__.py:2008–2144  ·  view source on GitHub ↗

Do basic configuration for the logging system. This function does nothing if the root logger already has handlers configured, unless the keyword argument *force* is set to ``True``. It is a convenience method intended for use by simple scripts to do one-shot configuration of th

(**kwargs)

Source from the content-addressed store, hash-verified

2006#---------------------------------------------------------------------------
2007
2008def basicConfig(**kwargs):
2009 """
2010 Do basic configuration for the logging system.
2011
2012 This function does nothing if the root logger already has handlers
2013 configured, unless the keyword argument *force* is set to ``True``.
2014 It is a convenience method intended for use by simple scripts
2015 to do one-shot configuration of the logging package.
2016
2017 The default behaviour is to create a StreamHandler which writes to
2018 sys.stderr, set a formatter using the BASIC_FORMAT format string, and
2019 add the handler to the root logger.
2020
2021 A number of optional keyword arguments may be specified, which can alter
2022 the default behaviour.
2023
2024 filename Specifies that a FileHandler be created, using the specified
2025 filename, rather than a StreamHandler.
2026 filemode Specifies the mode to open the file, if filename is specified
2027 (if filemode is unspecified, it defaults to 'a').
2028 format Use the specified format string for the handler.
2029 datefmt Use the specified date/time format.
2030 style If a format string is specified, use this to specify the
2031 type of format string (possible values '%', '{', '$', for
2032 %-formatting, :meth:`str.format` and :class:`string.Template`
2033 - defaults to '%').
2034 level Set the root logger level to the specified level.
2035 stream Use the specified stream to initialize the StreamHandler. Note
2036 that this argument is incompatible with 'filename' - if both
2037 are present, 'stream' is ignored.
2038 handlers If specified, this should be an iterable of already created
2039 handlers, which will be added to the root logger. Any handler
2040 in the list which does not have a formatter assigned will be
2041 assigned the formatter created in this function.
2042 force If this keyword is specified as true, any existing handlers
2043 attached to the root logger are removed and closed, before
2044 carrying out the configuration as specified by the other
2045 arguments.
2046 encoding If specified together with a filename, this encoding is passed to
2047 the created FileHandler, causing it to be used when the file is
2048 opened.
2049 errors If specified together with a filename, this value is passed to the
2050 created FileHandler, causing it to be used when the file is
2051 opened in text mode. If not specified, the default value is
2052 `backslashreplace`.
2053 formatter If specified, set this formatter instance for all involved
2054 handlers.
2055 If not specified, the default is to create and use an instance of
2056 `logging.Formatter` based on arguments 'format', 'datefmt' and
2057 'style'.
2058 When 'formatter' is specified together with any of the three
2059 arguments 'format', 'datefmt' and 'style', a `ValueError`
2060 is raised to signal that these arguments would lose meaning
2061 otherwise.
2062
2063 Note that you could specify a stream created using open(filename, mode)
2064 rather than passing the filename and mode in. However, it should be
2065 remembered that StreamHandler does not close its stream (since it may be

Callers 6

criticalFunction · 0.85
errorFunction · 0.85
warningFunction · 0.85
infoFunction · 0.85
debugFunction · 0.85
logFunction · 0.85

Calls 11

StreamHandlerClass · 0.85
removeHandlerMethod · 0.80
setFormatterMethod · 0.80
addHandlerMethod · 0.80
FileHandlerClass · 0.70
FormatterClass · 0.70
popMethod · 0.45
closeMethod · 0.45
joinMethod · 0.45
keysMethod · 0.45
setLevelMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…