How to export a logging level?

Discussion in 'Python' started by Vincent Vande Vyvre, Sep 25, 2012.

  1. 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>
    Vincent Vande Vyvre, Sep 25, 2012
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pabbu
    Replies:
    8
    Views:
    700
    Marc Boyer
    Nov 7, 2005
  2. Peter Otten

    Re: How to export a logging level?

    Peter Otten, Sep 25, 2012, in forum: Python
    Replies:
    0
    Views:
    162
    Peter Otten
    Sep 25, 2012
  3. Vincent Vande Vyvre

    Re: How to export a logging level?

    Vincent Vande Vyvre, Sep 25, 2012, in forum: Python
    Replies:
    0
    Views:
    169
    Vincent Vande Vyvre
    Sep 25, 2012
  4. Jean-Michel Pichavant

    Re: How to export a logging level?

    Jean-Michel Pichavant, Sep 25, 2012, in forum: Python
    Replies:
    0
    Views:
    180
    Jean-Michel Pichavant
    Sep 25, 2012
  5. Vincent Vande Vyvre

    Re: How to export a logging level?

    Vincent Vande Vyvre, Sep 25, 2012, in forum: Python
    Replies:
    0
    Views:
    180
    Vincent Vande Vyvre
    Sep 25, 2012
Loading...

Share This Page