ordigi/elodie/log.py

66 lines
1.2 KiB
Python
Raw Normal View History

2016-11-09 07:41:00 +01:00
"""
General file system methods.
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
"""
import sys
2016-11-09 07:41:00 +01:00
from json import dumps
from elodie import constants
def all(message):
_print(message)
2016-11-09 07:41:00 +01:00
def info(message):
_print_debug(message)
2016-11-09 07:41:00 +01:00
def info_json(payload):
_print_debug(dumps(payload))
2016-11-09 07:41:00 +01:00
def progress(message='.', new_line=False):
if not new_line:
print(message, end="")
else:
print(message)
2016-11-09 07:41:00 +01:00
def warn(message):
_print_debug(message)
2016-11-09 07:41:00 +01:00
def warn_json(payload):
_print_debug(dumps(payload))
2016-11-09 07:41:00 +01:00
def error(message):
_print_debug(message)
2016-11-09 07:41:00 +01:00
def error_json(payload):
_print_debug(dumps(payload))
2016-11-09 07:41:00 +01:00
def _print_debug(string):
# Print if debug == True or if running with nosetests
# Commenting out because this causes failures in other tests
# which verify that output is correct.
# Use the line below if you want output printed during tests.
# if(constants.debug is True or 'nose' in sys.modules.keys()):
2016-11-09 07:41:00 +01:00
if(constants.debug is True):
_print(string)
def _print(s):
try:
print(s)
except UnicodeEncodeError:
for c in s:
try:
print(c, end='')
except UnicodeEncodeError:
print('?', end='')