logging module -- better timestamp accuracy on Windows

Ross Ridge rridge at csclub.uwaterloo.ca
Tue Feb 15 22:11:31 EST 2011


benhoyt  <comp.lang.python at googlegroups.com> wrote:
>This works, but as you can see, it's a bit hacky. Is there a better way to =
>fix it? (I'd like the fix to affect all loggers, including the root logger.=
>)

A simpler solution would be to caclulate the time it takes to the handle
the request using time.clock() and include it in the log message.
Something like:

	timer = time.time
	if sys.platform == 'win32':
		timer = time.clock

	def handler(...):
		start = timer()
		...
		logging.debug("processing time %.0fms",
			      (timer() - start) * 1000)

Saves you from having to do the math in your head when you look at
the logs.

					Ross Ridge

-- 
 l/  //	  Ross Ridge -- The Great HTMU
[oo][oo]  rridge at csclub.uwaterloo.ca
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //	  



More information about the Python-list mailing list