I don't understand why you set up the logging like that. All you need is to do:
log = logging.getLogger("name")
That's it. Of course project-Wide, you add handlers once.
Diez
Am 16.12.2010 um 15:31 schrieb Sam <[email protected]>:
> I rely quite a bit on logging - and have implemented a pretty neat
> system where I store the logs both to disk and to memcached, so I can
> view them online easily.
>
> This works pretty well - except when I try to add logging to my
> model.py. Then every log call inside model.py results in five
> duplicate log entries.
>
> This is using TG 1.0
>
> Here's the relevant code:
>
>
> log = setup_logging_3('model')
>
> def setup_logging_3(log_name):
> log = logging.getLogger(log_name)
> formatter = logging.Formatter('%(asctime)s %(name)-12s %
> (levelname)-8s %(message)s')
>
> directory = os.path.join("/home/ockman", "logs3", version())
> try:
> os.makedirs(directory)
> except OSError:
> pass #Directory already exists
> log_filename = os.path.join(directory, log_name)
>
> lfh = logging.FileHandler(log_filename)
> lfh.setFormatter(formatter)
> log.addHandler(lfh)
>
> log.setLevel(logging.DEBUG)
>
> memhandler = memlogging.MemcachedHandler()
> print "Adding MemcachedHandler"
> log.addHandler(memhandler)
>
> console = logging.StreamHandler()
> console.setFormatter(formatter)
> log.addHandler(console)
>
> def exhook(type, value, backtrace):
> formatted = traceback.format_exception(type, value, backtrace)
> astring = "".join(formatted)
> log.error(astring)
> sys.excepthook = exhook
> return log
>
> Any ideas?
>
> Thanks
> Sam
>
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/turbogears?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en.