Home arrow GIS Data & Resources arrow Scripts and Code arrow Python arrow Python! Log files for Quality Control...
Python! Log files for Quality Control... PDF Print E-mail

Written by Kevin Bell,

Log files are very helpful for, well, logging I suppose. If you integrate the code below with a cursor of some variety you can document how features change or when they are created, or if certain values exist.

I use log files to document when traffic accident severity is altered, among other things. The police are constantly getting new data on traffic accidents, for example if someone is hurt really bad, then a week later the die, I have code that goes back through the records and tests each attribute of the accident, and if certain things change the log file is appended accordingly. Pushing the data to a table may make more sense in some cases so that a join could tie the info back to the map, but sometimes you just need to make some notes. My scripts often utilize logging to record the success or failure of complex geoprocessing routines.

Wrapping the logging code into a function often is a good way to handle things because you can pitch variables into the function so that maybe you always get a timestamp, but the other information reflects different items of interest.

Yours Truly,
The Lorax

import os
import time


#---create a logging file named "YYYYMMDD HH_MM_QualityControlLog.txt"
theTime = time.strftime('%Y%m%d %H_%M')
logfilename = "C:\\ProcessingLogs\\" + theTime + "_QualityControlLog.txt"

log = open(logfilename,'w')

log.write("Processing Traffic Studies" + "\n")
log.write("Began at: " + time.asctime() + "\n")
log.write("-------------------------------------" + "\n")


log.write("something has happened worth logging" + "\n")
log.write("stumps don't lie" + "\n")
log.write("just kidding... some do")


os.startfile("C:\\ProcessingLogs\\")

Users' Comments  
 

Display 1 of 1 comments

1. Mon, 12-08-2008 at 05:53 PM

Sean Gillies, from Ft. Collins sent me this link...perhaps a more elegant way to do this but a bit harder to grasp than Kevin's script. 
 
http://sgillies.net/blog/832/ python-logging/

Display 1 of 1 comments

Add your comment

04, Dec. 2008
Last Updated ( 04, Dec. 2008 )
 
< Prev   Next >

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2009 AGRC

Optimized for