adafruit_logging NOTSET does not disable Logging

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
c15571
 
Posts: 17
Joined: Mon Nov 28, 2011 8:48 pm

adafruit_logging NOTSET does not disable Logging

Post by c15571 »

Raspberry Pi Pico
CircuitPython version 7.3.1
adafruit_logging version 4.1.1

Running the example logging.simpletest from the library bundle with logger.setlevel set to NOTSET does not disable logging as documented.

Here is the code I ran.

Code: Select all

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# pylint:disable=undefined-variable,wildcard-import,no-name-in-module
# pylint:disable=no-member,invalid-name

"""Briefly exercise the logger and null logger."""

import adafruit_logging as logging

# This should produce an error output

logger = logging.getLogger("test")
print_logger = logging.StreamHandler()
logger.addHandler(print_logger)

logger.setLevel(logging.NOTSET)
logger.info("Info message\n")
logger.error("Error message\n")

# This should produce no output

null_logger = logging.getLogger("null")
null_handler = logging.NullHandler()
null_logger.addHandler(null_handler)

null_logger.setLevel(logging.ERROR)
null_logger.info("Info message")
null_logger.error("Error message")
The library documentation describes the use of NOTSET to disable output of log messages, but it doesn't seem to work. Is this a bug or am I doing something incorrectly?

The NullHandler section of code does work. Is this the recommended method to disable logging? Should the library documentation be updated?

Thanks in advance.

TonyC

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: adafruit_logging NOTSET does not disable Logging

Post by adafruit_support_carter »

Could be a bug. Quick look at the logic here:
https://github.com/adafruit/Adafruit_Ci ... ng.py#L313
and NOTSET=0, so it'll end up printing *all* levels.

Want to open an issue for this in the repo?
https://github.com/adafruit/Adafruit_Ci ... ing/issues

User avatar
c15571
 
Posts: 17
Joined: Mon Nov 28, 2011 8:48 pm

Re: adafruit_logging NOTSET does not disable Logging

Post by c15571 »

I opened issue #35.

Hope I provided enough information.

Thanks Carter!

TonyC

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”