-
Notifications
You must be signed in to change notification settings - Fork 0
Msglogfunction
johnnyquest edited this page Jun 9, 2011
·
4 revisions
(wip)
def msg(m):
msg = "[%s <scriptname>.py] %s" % (datetime.datetime.now().strftime("%y%m%d %H:%M.%S"), m)
sys.stderr.write(msg+"\n")
print msg
# TODO: write the other functions in the MEL code (or better, a factory function)
proc string ds() { return( string(`date -f "YYMMDD/hh:mm.ss"`) ); }
proc string ms( string $msg ) {
return("["+ds()+" <scriptname>]: "+$msg);
}
proc msg( string $msg ) { string $m=ms($msg); trace($m); if (!`about -b`) print("// "+$m+" //\n"); }
proc warn( string $msg ) { msg("WARNING: "+$msg); }
proc err( string $msg ) { msg("ERROR: "+$msg); }
proc dbg( string $msg ) { msg("(debug) "+$msg); }
I believe in adding lots of debug messages to my code (so it verbosely 'talks' about what it's doing). It always proves very useful in problem cases, but otherwise can be very annoying.
My solution was a log file viewer app which filters out lines with the (debug)
string in them by default (with a switch in the UI to allow viewing the 'debug' version of the log).