Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'scripts': 0.03; '"the': 0.07; '"__main__":': 0.09; '__name__': 0.09; 'main()': 0.09; 'subject:modules': 0.09; 'whichever': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'a.py': 0.16; 'b.py': 0.16; 'c.py': 0.16; 'eof': 0.16; 'imports': 0.16; 'logger': 0.16; 'modules,': 0.16; 'namespace.': 0.16; 'pythonic': 0.16; 'singleton': 0.16; 'wrote:': 0.18; 'module': 0.19; 'seems': 0.21; 'example': 0.22; 'import': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'skip:l 30': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'logging': 0.26; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'class': 0.32; 'url:python': 0.33; 'running': 0.33; 'moment': 0.34; '"the': 0.34; 'skip:_ 10': 0.34; 'maybe': 0.34; 'could': 0.34; "can't": 0.35; 'except': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'skip:& 10': 0.38; 'fact': 0.38; 'skip:& 20': 0.39; 'url:mail': 0.40; 'entire': 0.61; 'our': 0.64; 'subject:. ': 0.67; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=jnRcO4/lEaJ2335Vz2w1cgLccHcUxBq6tU/QFs0R1MU=; b=oNZw/KhszBaXeu9yDVg29zD90JcqwWiyOy5SsUujX+7K2FCL+QczBY+izKTsxwXqxP VfS6W12Uk60LlCNyktRlhaHZ/syZKJMtoR2fMIXy44x64Qkb4HWpmOXOn+keZ4nmbSJ9 JPnWBFuvokBmuGd2Guy3QpyNC/1C8AvsL5QlA9AINdUYnxm1KIdkIXwxcSYZM5AVsK8h GkoSa77VzU5dd+C9lAUWu0DAAIPMiR7P3GNfWQq/AAxe0T+ijo0O1+e56iT5J2N8ECLL U7rkgaKdzbIdF1DrBvKiL9ihwHclkkTrFcFOB6GOCg7y9GZ3E78IkxAVs7Hlsq1E2Xlh 936Q== MIME-Version: 1.0 X-Received: by 10.224.192.6 with SMTP id do6mr10724091qab.82.1366824576106; Wed, 24 Apr 2013 10:29:36 -0700 (PDT) In-Reply-To: References: Date: Wed, 24 Apr 2013 18:29:35 +0100 Subject: Re: improvements sought re. logging across modules From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: jkn+gg@nicorp.co.uk Content-Type: multipart/alternative; boundary=20cf300fb1cb55375404db1ea58d Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 163 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366824584 news.xs4all.nl 15886 [2001:888:2000:d::a6]:57432 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44275 --20cf300fb1cb55375404db1ea58d Content-Type: text/plain; charset=ISO-8859-1 Maybe import mylogger.mylogger as gLog? I don't know what you mean by "missing a trick". Your example seems pretty pythonic to me, except for the fact that you use a singleton where you could have a couple of functions and use the module as the namespace. On 24 Apr 2013 17:58, "The Night Tripper" wrote: > Hi all > I have a small suite of python modules, say > > A.py > B.py > C.py > > which can be invoked in a variety of ways. eg. > > 1) A.py is invoked directly; this imports and uses B.py and C.py > > 2) B.py is invoked; this imports and uses A.py and C.py > > I use the logging module in all of these python modules, and I want to be > able to use a single logger across the entire suite of whichever set of > scripts is running. > > The way I do this at the moment is to have a separate module mylogger.py: > > == mylogger.py == > > import logging > > class MyLogger: #using python 2.4 ;-o > def __init__(self): > self.log = logging.getLogger(MY_APP_NAME) > def setupLogging(self): > self.log.setlevel(logging.DEBUG) > # ... > > # our singleton logging object > mylogger = Mylogger() > # EOF > > and then in my other modules A.py, B.py etc. I have something like: > > == A.py == > > import mylogger > gLog = mylogger.mylogger > > if __name__ == "__main__": > gLog.setupLogging() > gLog.info("Module A running as main") > main() > #EOF > > == B.py == > > import mylogger > gLog = mylogger.mylogger > > if __name__ == "__main__": > gLog.setupLogging() > gLog.info("Module B running as main") > main() > # EOF > > This works, but I can't help thinking I'm missing a trick here. Any > suggestions? > > Thanks > j^n > > -- > http://mail.python.org/mailman/listinfo/python-list > --20cf300fb1cb55375404db1ea58d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Maybe import mylogger.mylogger as gLog? I don't know wha= t you mean by "missing a trick". Your example seems pretty python= ic to me, except for the fact that you use a singleton where you could have= a couple of functions and use the module as the namespace.

On 24 Apr 2013 17:58, "The Night Tripper&qu= ot; <jkn+gg@nicorp.co.uk>= ; wrote:
Hi all
=A0 =A0 =A0 =A0 I have a small suite of python modules, say

=A0 =A0 =A0 =A0 A.py
=A0 =A0 =A0 =A0 B.py
=A0 =A0 =A0 =A0 C.py

which can be invoked in a variety of ways. eg.

1) A.py is invoked directly; this imports and uses B.py and C.py

2) B.py is invoked; this imports and uses A.py and C.py

I use the logging module in all of these python modules, and I want to be able to use a single logger across the entire suite of whichever set of
scripts is running.

The way I do this at the moment is to have a separate module mylogger.py:
=3D=3D mylogger.py =3D=3D

import logging

class MyLogger: =A0 #using python 2.4 ;-o
=A0 =A0 def __init__(self):
=A0 =A0 =A0 =A0 self.log =3D logging.getLogger(MY_APP_NAME)
=A0 =A0 def setupLogging(self):
=A0 =A0 =A0 =A0 self.log.setlevel(logging.DEBUG)
=A0 =A0 =A0 =A0 # ...

# our singleton logging object
mylogger =3D Mylogger()
# EOF

and then in my other modules A.py, B.py etc. I have something like:

=3D=3D A.py =3D=3D

import mylogger
gLog =3D mylogger.mylogger

if __name__ =3D=3D "__main__":
=A0 =A0 gLog.setupLogging()
=A0 =A0 gLog.info("Module A running as main")
=A0 =A0 main()
#EOF

=3D=3D B.py =3D=3D

import mylogger
gLog =3D mylogger.mylogger

if __name__ =3D=3D "__main__":
=A0 =A0 gLog.setupLogging()
=A0 =A0 gLog.info("Module B running as main")
=A0 =A0 main()
# EOF

This works, but I can't help thinking I'm missing a trick here. Any=
suggestions?

=A0 =A0 Thanks
=A0 =A0 j^n

--
http://mail.python.org/mailman/listinfo/python-list
--20cf300fb1cb55375404db1ea58d--