Skip to content

Commit

Permalink
Added color and logging support for nodes
Browse files Browse the repository at this point in the history
* node/src/core/utility.py
  -- Added a platform check to colorize output
  -- Added a log and debug check
  -- We actually write output to a file now
  • Loading branch information
hatRiot committed Sep 3, 2014
1 parent 2a22172 commit b6162ec
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions node/src/core/utility.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
from datetime import date, datetime
from src.core.log import *
import platform
import config


def msg(string, level=INFO):
""" Handle messages; this takes care of logging and
debug checking, as well as output colors
"""
"""

if level is INFO:
print '\033[32m[%s] %s\033[0m' % (timestamp(), string)
elif level is DEBUG:
print '\033[34m[%s] %s\033[0m' % (timestamp(), string)
elif level is ERROR:
print '\033[31m[%s] %s\033[0m' % (timestamp(), string)
string = "[%s] %s" % (timestamp(), string)
if 'linux' in platform.platform().lower():
if level is INFO:
color_string = '%s%s%s' % ('\033[32m', string, '\033[0m')
elif level is DEBUG:
color_string = '%s%s%s' % ('\033[34m', string, '\033[0m')
elif level is ERROR:
color_string = '%s%s%s' % ('\033[31m', string, '\033[0m')
else:
color_string = string

if level is DEBUG and not config.DEBUG:
return

if not level is LOG:
print color_string

log(string)


def timestamp():
"""
""" Generate a timestamp
"""

return '%s %s' % (date.today().isoformat(),
Expand All @@ -26,4 +41,5 @@ def log(string):
""" Log string to file
"""

pass
with open(config.LOG_FILE, "a+") as f:
f.write("[%s] %s\n" % (timestamp(), string))

0 comments on commit b6162ec

Please sign in to comment.