Skip to content

Instantly share code, notes, and snippets.

@adarshdec23
Created December 3, 2016 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adarshdec23/c57c7667f2ccd60b3ff593daf4ab3730 to your computer and use it in GitHub Desktop.
Save adarshdec23/c57c7667f2ccd60b3ff593daf4ab3730 to your computer and use it in GitHub Desktop.
A python method to write logs to the console.
from datetime import datetime
def ConsoleWrite(messageType, message, variable = None):
print datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
print "[" + messageType + "]\t",
if variable:
print type(variable).__name__, ":", message
print(variable)
else:
print message
ConsoleWrite("INFO", "Program staring...")
ConsoleWrite("WARNING", "Some warning")
a = {
"hello":"world",
"numbers":[
1,
2,
3]
}
ConsoleWrite("DEBUG", "a", a)
ConsoleWrite("INFO", "Program terminating...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment