How to define a different registrar for an imported module in Python?

I am using Advanced Python Scheduler in a Python script. The main program defines the log by calling logging.basicConfig with the name of the log file I want. This log is also set as "DEBUG" as the logging level, as this is what I currently need for my script.

Unfortunately, since logging.basicConfig is configured this way, apscheduler writes log entries to the same log file. There are a lot of them, especially since I have one scheduled task that runs every minute.

Is there a way to redirect the output of apscheduler log to another log file (without changing the apscheduler code) when using my log file for my own script? That is, is there a way to change the file name for each module output in my script?

I tried reading the page and the HOWTO for logging, but could not find the answer to this question.

+4
source share
2 answers

Set the log level for apscheduler to the desired value (for example, WARNING , so that you do not see DEBUG and INFO apscheduler with apscheduler as follows:

 logging.getLogger('apscheduler').setLevel(logging.WARNING) 

You will still receive messages for WARNING and higher degrees. To direct messages from apscheduler to a separate file, use

 aplogger = logging.getLogger('apscheduler') aplogger.propagate = False aplogger.setLevel(logging.WARNING) # or whatever aphandler = logging.FileHandler(...) # as per what you want aplogger.addHandler(aphandler) 

Make sure that the above code is called only once (otherwise you will add multiple instances of FileHandler - maybe not what you want).

+2
source

Perhaps you want to call logging.getLogger ("apscheduler") and set up your log file there? see this answer fooobar.com/questions/861410 / ...

0
source

Source: https://habr.com/ru/post/1495092/


All Articles