Code should avoid usage of basicConfig() to set up logging since subsequent calls by library users might fail silently.
The function basicConfig() sets up the root Logger with a StreamHandler.
Since basicConfig() function "does nothing if the root logger already has handlers configured", after g4f code calls it library users will always experience silent failure when calling it again (issue #2274).
Note that configuration of the root logger should be avoided by libraries (see Configuring Logging for a Library - Python Docs).
Logging functions are called from root logger. This is not a recommended practice and can interfere with custom logging setups (log duplication issue #2173) and third-party libraries.
There is leftover unused code in g4f/api/_logging.py, which sets up handlers with basicConfig(). If called it might fail silently, since there's another basicConfig() call in g4f/Provider/you/har_file.py#L14 (see issue 1).
Module Loguru is only imported here, so it's unused as well.
Proposed solutions
Replace call to basicConfig() with setLevel()
Create a named Logger for the library.
Remove or comment out unused code and remove Loguru dependency.
Info: Current code sets logging error level to ERROR.
Current logging implementation needs improvement.
Issues
Code should avoid usage of basicConfig() to set up logging since subsequent calls by library users might fail silently. The function
basicConfig()
sets up the root Logger with a StreamHandler. SincebasicConfig()
function "does nothing if the root logger already has handlers configured", after g4f code calls it library users will always experience silent failure when calling it again (issue #2274). Note that configuration of the root logger should be avoided by libraries (see Configuring Logging for a Library - Python Docs).Logging functions are called from root logger. This is not a recommended practice and can interfere with custom logging setups (log duplication issue #2173) and third-party libraries.
There is leftover unused code in g4f/api/_logging.py, which sets up handlers with basicConfig(). If called it might fail silently, since there's another
basicConfig()
call in g4f/Provider/you/har_file.py#L14 (see issue 1). Module Loguru is only imported here, so it's unused as well.Proposed solutions
basicConfig()
with setLevel()Info: Current code sets logging error level to ERROR.