mirror of
https://github.com/gryf/coach.git
synced 2025-12-17 19:20:19 +01:00
Modifying ScreenLogger to optionally not output color codes (#56)
* Modifying ScreenLogger to not output color when configured by new CLI parameter
This commit is contained in:
committed by
Scott Leishman
parent
7e7006305a
commit
d75df17d97
@@ -408,6 +408,9 @@ def main():
|
|||||||
help="(flag) TensorFlow verbosity level",
|
help="(flag) TensorFlow verbosity level",
|
||||||
default=3,
|
default=3,
|
||||||
type=int)
|
type=int)
|
||||||
|
parser.add_argument('--nocolor',
|
||||||
|
help="(flag) Turn off color-codes in screen logging. Ascii text only",
|
||||||
|
action='store_true')
|
||||||
parser.add_argument('-s', '--checkpoint_save_secs',
|
parser.add_argument('-s', '--checkpoint_save_secs',
|
||||||
help="(int) Time in seconds between saving checkpoints of the model.",
|
help="(int) Time in seconds between saving checkpoints of the model.",
|
||||||
default=None,
|
default=None,
|
||||||
@@ -495,6 +498,9 @@ def main():
|
|||||||
|
|
||||||
args = parse_arguments(parser)
|
args = parse_arguments(parser)
|
||||||
|
|
||||||
|
if args.nocolor:
|
||||||
|
screen.set_use_colors(False)
|
||||||
|
|
||||||
graph_manager = get_graph_manager_from_args(args)
|
graph_manager = get_graph_manager_from_args(args)
|
||||||
|
|
||||||
if args.distributed_coach and not graph_manager.agent_params.algorithm.distributed_coach_synchronization_type:
|
if args.distributed_coach and not graph_manager.agent_params.algorithm.distributed_coach_synchronization_type:
|
||||||
|
|||||||
@@ -57,8 +57,26 @@ class Colors(object):
|
|||||||
|
|
||||||
# prints to screen with a prefix identifying the origin of the print
|
# prints to screen with a prefix identifying the origin of the print
|
||||||
class ScreenLogger(object):
|
class ScreenLogger(object):
|
||||||
def __init__(self, name):
|
def __init__(self, name, use_colors=True):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.set_use_colors(use_colors)
|
||||||
|
|
||||||
|
def set_use_colors(self, use_colors):
|
||||||
|
self._use_colors = use_colors
|
||||||
|
if use_colors:
|
||||||
|
self._prefix_success = Colors.GREEN
|
||||||
|
self._prefix_warning = Colors.YELLOW
|
||||||
|
self._prefix_error = Colors.RED
|
||||||
|
self._prefix_title = Colors.BG_CYAN
|
||||||
|
self._prefix_ask = Colors.BG_CYAN
|
||||||
|
self._suffix = Colors.END
|
||||||
|
else:
|
||||||
|
self._prefix_success = ""
|
||||||
|
self._prefix_warning = "!! "
|
||||||
|
self._prefix_error = "!!!! "
|
||||||
|
self._prefix_title = "## "
|
||||||
|
self._prefix_ask = ""
|
||||||
|
self._suffix = ""
|
||||||
|
|
||||||
def separator(self):
|
def separator(self):
|
||||||
print("")
|
print("")
|
||||||
@@ -68,29 +86,35 @@ class ScreenLogger(object):
|
|||||||
def log(self, data):
|
def log(self, data):
|
||||||
print(data)
|
print(data)
|
||||||
|
|
||||||
def log_dict(self, dict, prefix=""):
|
def log_dict(self, data, prefix=""):
|
||||||
str = "{}{}{} - ".format(Colors.PURPLE, prefix, Colors.END)
|
if self._use_colors:
|
||||||
for k, v in dict.items():
|
str = "{}{}{} - ".format(Colors.PURPLE, prefix, Colors.END)
|
||||||
str += "{}{}: {}{} ".format(Colors.BLUE, k, Colors.END, v)
|
for k, v in data.items():
|
||||||
print(str)
|
str += "{}{}: {}{} ".format(Colors.BLUE, k, Colors.END, v)
|
||||||
|
print(str)
|
||||||
|
else:
|
||||||
|
logentries = []
|
||||||
|
for k, v in data.items():
|
||||||
|
logentries.append("{}={}".format(k, v))
|
||||||
|
logline = "{}> {}".format(prefix, ", ".join(logentries))
|
||||||
|
print(logline)
|
||||||
|
|
||||||
def log_title(self, title):
|
def log_title(self, title):
|
||||||
print("{}{}{}".format(Colors.BG_CYAN, title, Colors.END))
|
print("{}{}{}".format(self._prefix_title, title, self._suffix))
|
||||||
|
|
||||||
def success(self, text):
|
def success(self, text):
|
||||||
print("{}{}{}".format(Colors.GREEN, text, Colors.END))
|
print("{}{}{}".format(self._prefix_success, text, self._suffix))
|
||||||
|
|
||||||
def warning(self, text):
|
def warning(self, text):
|
||||||
print("{}{}{}".format(Colors.YELLOW, text, Colors.END))
|
print("{}{}{}".format(self._prefix_warning, text, self._suffix))
|
||||||
|
|
||||||
def error(self, text, crash=True):
|
def error(self, text, crash=True):
|
||||||
print("{}{}{}".format(Colors.RED, text, Colors.END))
|
print("{}{}{}".format(self._prefix_error, text, self._suffix))
|
||||||
if crash:
|
if crash:
|
||||||
atexit.unregister(summarize_experiment)
|
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
def ask_input(self, title):
|
def ask_input(self, title):
|
||||||
return input("{}{}{}".format(Colors.BG_CYAN, title, Colors.END))
|
return input("{}{}{}".format(self._prefix_ask, title, self._suffix))
|
||||||
|
|
||||||
def ask_input_with_timeout(self, title, timeout, msg_if_timeout='Timeout expired.'):
|
def ask_input_with_timeout(self, title, timeout, msg_if_timeout='Timeout expired.'):
|
||||||
class TimeoutExpired(Exception):
|
class TimeoutExpired(Exception):
|
||||||
@@ -125,7 +149,7 @@ class ScreenLogger(object):
|
|||||||
default_answer = 'y/N'
|
default_answer = 'y/N'
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
answer = input("{}{}{} ({})".format(Colors.BG_CYAN, title, Colors.END, default_answer))
|
answer = input("{}{}{} ({})".format(self._prefix_ask, title, self._suffix, default_answer))
|
||||||
if answer == "yes" or answer == "YES" or answer == "y" or answer == "Y":
|
if answer == "yes" or answer == "YES" or answer == "y" or answer == "Y":
|
||||||
return True
|
return True
|
||||||
elif answer == "no" or answer == "NO" or answer == "n" or answer == "N":
|
elif answer == "no" or answer == "NO" or answer == "n" or answer == "N":
|
||||||
@@ -140,7 +164,10 @@ class ScreenLogger(object):
|
|||||||
:param title: The new title
|
:param title: The new title
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
print("\x1b]2;{}\x07".format(title))
|
if self._use_colors:
|
||||||
|
print("\x1b]2;{}\x07".format(title))
|
||||||
|
else:
|
||||||
|
print("Title: %s" % title)
|
||||||
|
|
||||||
|
|
||||||
class BaseLogger(object):
|
class BaseLogger(object):
|
||||||
@@ -397,5 +424,6 @@ def get_experiment_path(experiment_name, create_path=True):
|
|||||||
os.makedirs(experiment_path)
|
os.makedirs(experiment_path)
|
||||||
return experiment_path
|
return experiment_path
|
||||||
|
|
||||||
|
|
||||||
global screen
|
global screen
|
||||||
screen = ScreenLogger("")
|
screen = ScreenLogger("")
|
||||||
|
|||||||
Reference in New Issue
Block a user