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


Groups > comp.lang.python > #30116

Re: How to export a logging level?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin.stu.neva.ru!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <vincent.vandevyvre@swing.be>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'configure': 0.04; 'root': 0.04; 'url:launchpad': 0.05; 'level,': 0.07; 'subject:How': 0.09; 'advice.': 0.09; 'logger': 0.09; 'def': 0.10; 'from:addr:swing.be': 0.16; 'from:addr:vincent.vandevyvre': 0.16; 'from:name:vincent vande vyvre': 0.16; 'log.': 0.16; 'message- id:@swing.be': 0.16; 'module).': 0.16; 'oqapy': 0.16; 'paqager': 0.16; 'received:mobistar.be': 0.16; 'simpler,': 0.16; 'subject:export': 0.16; 'url:oqapy': 0.16; 'url:paqager': 0.16; 'url:qarte': 0.16; 'v.v.': 0.16; '(in': 0.18; 'app': 0.19; 'module': 0.19; 'are:': 0.20; 'skip:" 30': 0.20; 'import': 0.21; 'skip:% 10': 0.22; 'work.': 0.23; 'task': 0.23; "i've": 0.23; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'logging': 0.27; 'module.': 0.27; 'lines': 0.28; 'url:mailman': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'related': 0.30; 'that.': 0.30; 'code': 0.31; 'url:python': 0.32; 'file': 0.32; '-----': 0.32; 'url:listinfo': 0.32; 'to:addr:python-list': 0.33; 'thanks': 0.34; 'skip:l 30': 0.35; 'subject:?': 0.35; 'but': 0.36; 'url:org': 0.36; 'anything': 0.36; 'should': 0.36; 'level': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'application': 0.40; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'url:mail': 0.40; 'your': 0.60; 'received:80.12': 0.65; 'life': 0.66; 'ever.': 0.84; 'processed,': 0.84; 'worthless': 0.84; 'forgotten': 0.91
Date Tue, 25 Sep 2012 20:11:47 +0200
From Vincent Vande Vyvre <vincent.vandevyvre@swing.be>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120827 Thunderbird/15.0
MIME-Version 1.0
To Python mail-list <python-list@python.org>
Subject Re: How to export a logging level?
References <276124593.587150.1348595240697.JavaMail.root@sequans.com>
In-Reply-To <276124593.587150.1348595240697.JavaMail.root@sequans.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1364.1348596710.27098.python-list@python.org> (permalink)
Lines 67
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348596710 news.xs4all.nl 6885 [2001:888:2000:d::a6]:58848
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:30116

Show key headers only | View raw


Le 25/09/12 19:47, Jean-Michel Pichavant a écrit :
> ----- Original Message -----
>> 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>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> Life is actually simpler, one rule to remember: you don't configure your loggers, ever. You let this worthless task to the user (in your case the main.py file or however import your module).
>
> In myfile.py, the only logging related lines are:
>
> import logging
> logger = logging.getLogger(__name_)
>
> Then you just log. How the logs  are processed, at which level, for which formatter, you don't care. The root logger will take care of that. Keep your main.py as it is and it should work.
>
> JM
>
>
Oops, my fault, I've forgotten a line "logger.setLevel(logging.WARNING)"
into my module.

Thanks
-- 
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

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

csiph-web