Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45675
| From | John Gordon <gordon@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: @staticmethods called more than once |
| Date | 2013-05-21 16:34 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <kng7n6$efc$1@reader1.panix.com> (permalink) |
| References | <02f0123d-2f9e-4287-b983-cfa1db9db69c@googlegroups.com> |
In <02f0123d-2f9e-4287-b983-cfa1db9db69c@googlegroups.com> Christian <mining.facts@gmail.com> writes:
> Hi,
> i'm somewhat confused working with @staticmethods. My logger and configuration methods are called n times, but I have only one call.
> n is number of classes which import the loger and configuration class
> in the subfolder mymodule. What might be my mistake mistake?
> Many thanks
> Christian
> ### __init__.py ###
> from mymodule.MyLogger import MyLogger
> from mymodule.MyConfig import MyConfig
> ##### my_test.py ##########
> from mymodule import MyConfig,MyLogger
> #Both methods are static
> key,logfile,loglevel = MyConfig().get_config('Logging')
> log = MyLogger.set_logger(key,logfile,loglevel)
> log.critical(time.time())
> #Output
> 2013-05-21 17:20:37,192 - my_test - 17 - CRITICAL - 1369149637.19
> 2013-05-21 17:20:37,192 - my_test - 17 - CRITICAL - 1369149637.19
> 2013-05-21 17:20:37,192 - my_test - 17 - CRITICAL - 1369149637.19
> 2013-05-21 17:20:37,192 - my_test - 17 - CRITICAL - 1369149637.19
You haven't given us the code for your MyLogger class, so it's difficult
to say exactly what the problem is.
However, I have a guess. Does MyLogger.set_logger() contain a call to
addHandler()? Each call to addHandler() adds another handler to your
logger, and when you call log.critical() [or any other log function] you
get one line of output for each handler.
You should only call addHandler() once.
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
@staticmethods called more than once Christian <mining.facts@gmail.com> - 2013-05-21 08:26 -0700
Re: @staticmethods called more than once Skip Montanaro <skip@pobox.com> - 2013-05-21 10:39 -0500
Re: @staticmethods called more than once John Gordon <gordon@panix.com> - 2013-05-21 16:34 +0000
Re: @staticmethods called more than once John Gordon <gordon@panix.com> - 2013-05-21 16:48 +0000
Re: @staticmethods called more than once Christian <mining.facts@gmail.com> - 2013-05-21 10:17 -0700
Re: @staticmethods called more than once Ethan Furman <ethan@stoneleaf.us> - 2013-05-21 09:30 -0700
Re: @staticmethods called more than once 88888 Dihedral <dihedral88888@googlemail.com> - 2013-05-21 18:23 -0700
csiph-web