How to export a logging level?

  • Thread starter Vincent Vande Vyvre
  • Start date
V

Vincent Vande Vyvre

In my application I import a module and I want to set the same logging
level
as the main app to this module.

I've tried this code

main.py

import logging
logger = logging.getLogger(__name__)
lvl = logging.DEBUG
LOG_FORMAT = "%(asctime)-6s %(levelname)s: %(name)s - %(message)s"
logging.basicConfig(format=LOG_FORMAT, datefmt='%H:%M:%S', level=lvl)

from mymodule.myfile import MyClass

....
def load_myclass(self):
lvl = logger.getEffectiveLevel()
mc = MyClass(self, lvl)


myfile.py

import logging
logger = logging.getLogger(__name__)

class MyClass(object):
def __init__(self, main, lvl):
logger.setLevel(lvl)

If I set the level to logging.DEBUG I can see all infos from the main
but anything
from my module.

Thanks for your advice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top