Python Forum
Logging /w several modules/libraries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Logging /w several modules/libraries
#4
I have found an answer to my original question, within the logging package. I am still looking at the filter option.

Staying inline with my OP I want to easily, temporally, eliminate the logging "clutter" from module fan (assume the fan is not related to what we are currently working on.)

The following line of code can be added to in the main file, TT3.py, after line 15, the basic logger configuration. The line could also be added to the fan module.

logging.getLogger("fan").propagate = False
This line will stop the "propagation" of log records from module/logger "fan" up to its parent logger, in this case "root". Setting propagate to True (the default) will again include all level appropriate log lines in the output.

A related solution is to include a line like the following. Again it can be put in the main file after the basic configuration.

logging.getLogger("fan").level = logging.WARNING
This changes the logging level for the named logger only so the debug and info lines from "fan" are blocked but warning and higher lines are included. They may be informative.

In my current project code is divided into ~10 modules/classes with 2 custom libraries. Each module is at a different level of completion with some details stubbed out so all the interfaces work, but without some functionality.
With versions of the two lines above I can limit logging to the area I am currently working on without removing and later replacing monitoring lines in other modules. That remove-and-replace scenario is what I wanted to avoid by switching from 'print' to logging.

Placing all the .propagate and .level lines in the main file keeps all the controls in one place.
Say what you will about Sisyphus. He always has work.
Reply


Messages In This Thread
Logging /w several modules/libraries - by Lou - Sep-08-2021, 07:38 AM
RE: Logging /w several modules/libraries - by Lou - Sep-11-2021, 12:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  List of Modules/Libraries Installed by Default? rontarrant 2 1,044 Oct-14-2022, 05:18 PM
Last Post: rontarrant
Question Trouble installing modules/libraries and getting Notepad++ to show cyrillic letters Dragiev 6 2,324 Jul-24-2022, 12:55 PM
Last Post: Dragiev
  Modules issue, pip3 download modules only to pyhton3.5.2 not the latest 3.6.1 bmohanraj91 6 8,518 May-25-2017, 08:15 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020