I'm writing a server app which should be able to log at different levels both on the console and a log file.
The problem is, if logging.basicConfig()
is set it will log to the console but it must be set in the main thread.
It can also be set with logging.basicConfig(filename='logger.log')
to write to a file.
Setting a handle either for console logging (logging.StreamHandler()
) or file logging (logging.FileHandler()
) complements the logging.baseconfig()
option set.
The problem is, that the settings are not independent.
What I mean is, the loglevel of logging.baseConfig()
must include the Handler level, or it wont be logged.
So if I set the baseConfig
to log to file, and a StreamHandler
to log to console, the file loglevel must be lower than the console level.
(Also, the basicConfig
option logs all other logs.)
I tried to create two Handles, one for the console and one for the log file, they work, but whatever log type is specified by basicConfig()
will still be displayed duplicating messages.
Is there a way to disable the output of basicConfig()
?
Or any other way to implement these options?