Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'root': 0.05; '"""': 0.07; '*args,': 0.09; 'hierarchical': 0.09; 'subject:module': 0.09; 'def': 0.12; '"module"': 0.16; 'args,': 0.16; 'attribute,': 0.16; 'logger': 0.16; 'pythonic': 0.16; 'subject:Logging': 0.16; 'wrote:': 0.18; 'module': 0.19; 'stack': 0.19; 'email addr:gmail.com>': 0.22; 'module,': 0.24; '>': 0.26; 'define': 0.26; 'logging': 0.26; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'wondering': 0.29; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'gives': 0.31; 'this.': 0.32; 'common': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'level': 0.37; 'performance': 0.37; 'skip:& 10': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'skip:& 20': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'logged': 0.60; 'name': 0.63; 'believe': 0.68; 'mar': 0.68; '2015': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=HcXXvaLSB+HGPzkjCWmSamq+seOCmhPWuKmrCXuHEXo=; b=S/PM7tPSLcapWZvPEHy2IPk0Cy2ynYN/57mGvNDKo6Ut8jsP5yvbJTgH2f1iyLzzmK jeJ4cw5RFfWVqJ7hCQti0ynU03xA9VzoTm1ec0pkmQvVCUJzQWgEQoaTQlAoIXJLD/ku mOOH/b2IPN2KFUNGRtE2+vLeASpFw852f72MX38XRIkarR+3QVu9db7w6zix1q6botQI GkPnScNZQNhZf6aHpSdly5FiqqnYg94Acbg0EZYozImIjzyVjYawEI1QuIfj6StyIMX3 OXEKpAZ+sLv0kp+M5dcdO0KPs/MJubLd10bHApToOrYWCUNJk+9ku180Tmp5bk0G7MGw xCzw== MIME-Version: 1.0 X-Received: by 10.68.65.75 with SMTP id v11mr20376532pbs.10.1425396645514; Tue, 03 Mar 2015 07:30:45 -0800 (PST) In-Reply-To: References: <6676f6f6-94bf-4ed9-9a09-46beb4317e6c@googlegroups.com> Date: Tue, 3 Mar 2015 08:30:45 -0700 Subject: Re: Logging custom level not print module properly?? From: Ian Kelly To: Python Content-Type: multipart/alternative; boundary=001a1138029eb85554051064040e X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1425396648 news.xs4all.nl 2849 [2001:888:2000:d::a6]:34172 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86850 --001a1138029eb85554051064040e Content-Type: text/plain; charset=UTF-8 On Mar 3, 2015 8:16 AM, "Didymus" wrote: > I did find that if I changed the "self.log" to "self._log" it works correctly but gives me a pylint warning about acccess to a protected member _log.. > > def pwarning(self, message, *args, **kws): > """ Performance Warning Message Level """ > # Yes, logger takes its '*args' as 'args'. > self._log(PWARNING_NUM, message, args, **kws) > > Still wondering what the correct Pythonic way to handle this. I believe the common approach is to let each module define and use its own hierarchical logger named after the module, rather than have them all share the root logger. This way the name that is logged is based on which logger was used for logging and doesn't rely on the "module" attribute, which is populated through the vagaries of stack inspection. --001a1138029eb85554051064040e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Mar 3, 2015 8:16 AM, "Didymus" <lynto28@gmail.com> wrote:
> I did find that if I changed the "self.log" to "self._l= og" it works correctly but gives me a pylint warning about acccess to = a protected member _log..
>
> def pwarning(self, message, *args, **kws):
> =C2=A0 =C2=A0 """ Performance Warning Message Level &qu= ot;""
> =C2=A0 =C2=A0 # Yes, logger takes its '*args' as 'args'= ;.
> =C2=A0 =C2=A0 self._log(PWARNING_NUM, message, args, **kws)
>
> Still wondering what the correct Pythonic way to handle this.

I believe the common approach is to let each module define a= nd use its own hierarchical logger named after the module, rather than have= them all share the root logger. This way the name that is logged is based = on which logger was used for logging and doesn't rely on the "modu= le" attribute, which is populated through the vagaries of stack inspec= tion.

--001a1138029eb85554051064040e--