1. Travis Shirk
  2. eyeD3
  3. Issues
Issue #91 resolved

Don't configure global logging settings when imported as a library

gruns
created an issue

src/eyed3/utils/log.py changes global logging configuration. That's fine when eyeD3 is used as a CLI tool, but not when eyeD3 is imported by other code. Libraries shouldn't change global logging configuration.

One simple solution is to expose _initLogging() in log.py and move initLogging() to src/eyed3/main.py.

Until fixed, if anyone bumps into this problem, a workaround is to revert eyeD3's global logging modifications post import, like

import eyed3
logging.getLogger().handlers.pop()
logging.setLoggerClass(logging.Logger)

Comments (4)

  1. Isaac Hailperin

    Thank you for the hint!

    In order for eyed3 logging to fit into my applications logging, I had to add

    ch = logging.StreamHandler()
    ch.setLevel(LOG_LEVELS[args.verbosity_level])
    ch_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch.setFormatter(ch_formatter)
    # this is the relevant part, the previous is just for context
    eyed3.utils.log.log.handlers.pop()
    eyed3.utils.log.log.addHandler(ch) 
    

    Just in case it helps anyone.

  2. Log in to comment