jebena / jebena-python-client

Simple Python Client for the Jebena API Server
Mozilla Public License 2.0
2 stars 1 forks source link

No handlers could be found for logger "jebenaclient" #16

Closed bretty-mcbrettface closed 3 years ago

bretty-mcbrettface commented 3 years ago

This pops up every so often when I'm running my pipeline script. Could it have something to do with LOGGER = logging.getLogger("jebenaclient") rather than __name__? I'm honestly not sure what's happening.

bretty-mcbrettface commented 3 years ago

@jpotter This doesn't quite work. for some reason, having basicconfig in the jebena cli is completely overwriting my carefully-made settings for my own logger:

class LoggingFilter(logging.Filter):
    def filter(self, rec):
        return rec.levelno < LOG_LEVEL_ERR

logger = logging.getLogger(__name__)
logger.setLevel(LOG_LEVEL_MIN)
formatter = logging.Formatter(LOG_FORMAT)

h1 = logging.StreamHandler(sys.stdout)
h1.setLevel(LOG_LEVEL_MIN)
h1.setFormatter(formatter)
h1.addFilter(LoggingFilter())  # sends anything below LOG_LEVEL_ERR to stdout
h2 = logging.StreamHandler()
h2.setLevel(LOG_LEVEL_ERR)  # sends anything at LOG_LEVEL_ERR or above to stderr
h2.setFormatter(formatter)

logger.addHandler(h1)
logger.addHandler(h2)

This sends error and above to stderr and stdout otherwise. however, the basicconfig approach is somehow changing my logger to output everything to stderr.

jpotter commented 3 years ago

@bretty-mcbrettface This makes sense, alas -- the notes in https://github.com/jebena/jebena-python-client/pull/18 hint at the issue. Try initialing your logger before you do the import of jebenacli -- does that resolve it? We could refactor the client code to not use LOGGER at a module level, and instead lazy-load it at access time; maybe that'd step around this issue?

bretty-mcbrettface commented 3 years ago

I feel like it only makes sense to do it after the import...I guess I could try the opposite.

jpotter commented 3 years ago

The implemented solution for calling logging.basicConfig in Python2 conflicts for envs that also call a logging config() function.