
On Fri, Jun 14, 2013 at 4:47 PM, <exarkun@twistedmatrix.com> wrote:
On 07:45 pm, radix@twistedmatrix.com wrote:
I think both of these should be avoided because they require the user to specify string interpolation themselves. I'd prefer to avoid that entirely, by default.
log.msg("Foo happened**", bar=bar, baz=baz, boz=boz)
This is better because:
1. it keeps the data structured 2. it is a lot less typing
** I would prefer this part to be "foo", but I'll keep these discussions separate :)
I think that I agree with this, except I wonder if you could supply some more realistic examples here. Let's say I have a somewhat complex 50kloc application with a log event emitted around once every 10 lines.
After I use up "foo", "bar", "baz", and "quux" I start having to refer to the hacker dictionary. This doesn't get me very close to the 5000 event identifiers I'll need. How does someone come up with this in the real world?
Jean-Paul
This really should have been a response to my earlier message where I talk about the "event" more directly, instead my post about how to do string formatting, but anyway. That was a very amusing post, but I guess you were trying to make a point :) The event name shouldn't be meaningless; you or your ops team or your users are going to want to type it into their filtering software, and it's nice if they can keep the event name in their head. I find it most valuable when it's a short identifier that I think up with my brain and type into my program. If I'm logging in a call to received_frag(), for example, I'd probably call the event name "frag". If I'm logging a message about an error that occurred during a regularly scheduled database compaction, I would call it "scheduled-db-compact-failed". 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. -- Christopher Armstrong http://radix.twistedmatrix.com/ http://planet-if.com/