Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30109

How to export a logging level?

Date 2012-09-25 18:15 +0200
From Vincent Vande Vyvre <vincent.vandevyvre@swing.be>
Subject How to export a logging level?
Newsgroups comp.lang.python
Message-ID <mailman.1356.1348590190.27098.python-list@python.org> (permalink)

Show all headers | View raw


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.
-- 
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

How to export a logging level? Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2012-09-25 18:15 +0200

csiph-web