[Twisted-Python] logging

Christopher Armstrong radix at twistedmatrix.com
Fri Jun 14 16:45:23 MDT 2013


On Fri, Jun 14, 2013 at 5:43 PM, Christopher Armstrong
<radix at twistedmatrix.com> wrote:
> If you're concerned about universal uniqueness, there are two ways I
> can think of doing it, both of which should basically have a similar
> API as far as where concerns are in your code:
>
> - make the event name hierarchical with a root being identifier by your project
>
> "SpaceCombat.server.db.scheduled-compaction-failed"
>
> (you shouldn't need to type out this full event name every time you
> type a log.msg() statement; that's not a hard problem to solve)
>
> - put a hierarchical designator into the "system" field
>
> log("scheduled-compaction-failed", system="SpaceCombat.server.db")
>
> I think I like the idea of using "system" for this, since that
> basically seems like the original intent.


Sorry, let me clarify. You shouldn't need to type out
"SpaceCombat.server.db" multiple times in your log statements *ever*,
in either case above. I imagine a system like the following:

spacecombat/server/db.py:

from twisted.python import log

logger = log.BoundLogger(log, system="SpaceCombat.server.db")

logger.msg("scheduled-compaction-failed")

--
Christopher Armstrong
http://radix.twistedmatrix.com/
http://planet-if.com/



More information about the Twisted-Python mailing list