Skip to content

Instantly share code, notes, and snippets.

@dsibilly
Last active August 29, 2015 14:06
Show Gist options
  • Save dsibilly/c7e3bc704ec7b0218cf9 to your computer and use it in GitHub Desktop.
Save dsibilly/c7e3bc704ec7b0218cf9 to your computer and use it in GitHub Desktop.
Print line numbers and time in Python 3
#!/usr/bin/env python3
from datetime import datetime
from inspect import currentframe, getframeinfo
def niceLog(msg):
frameinfo = getframeinfo(currentframe().f_back)
print(" ".join([frameinfo.filename, "Line", str(frameinfo.lineno), datetime.now().strftime("%Y-%m-%d %H:%M:%S"), msg]))
if __name__ == "__main__":
niceLog('This is a test')
niceLog('This is another test')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment