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


Groups > comp.lang.python > #44275

Re: improvements sought re. logging across modules

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 <fabiosantosart@gmail.com>
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; '&quot;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 <D9OdncANCNCqk-XMnZ2dnUVZ8sOdnZ2d@brightview.co.uk>
References <D9OdncANCNCqk-XMnZ2dnUVZ8sOdnZ2d@brightview.co.uk>
Date Wed, 24 Apr 2013 18:29:35 +0100
Subject Re: improvements sought re. logging across modules
From Fábio Santos <fabiosantosart@gmail.com>
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 <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.1023.1366824584.3114.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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" <jkn+gg@nicorp.co.uk> 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
>

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


Thread

improvements sought re. logging across modules The Night Tripper <jkn+gg@nicorp.co.uk> - 2013-04-24 17:54 +0100
  Re: improvements sought re. logging across modules Fábio Santos <fabiosantosart@gmail.com> - 2013-04-24 18:29 +0100
  Re: improvements sought re. logging across modules Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-04-24 19:43 +0200
  Re: improvements sought re. logging across modules Dave Angel <davea@davea.name> - 2013-04-24 13:55 -0400

csiph-web