-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Colored output (issues #65) #141
Conversation
sebs/color.py
Outdated
class ColoredPrinter: | ||
@staticmethod | ||
def print(color, logging_instance, message): | ||
timestamp = datetime.datetime.now().strftime("%H:%M:%S") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we still display milliseconds in the timestamp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Fixed :D
sebs.py
Outdated
output_dir = sebs.utils.create_output(output_dir, preserve_out, verbose) | ||
sebs_client.logging.info("Created experiment output at {}".format(output_dir)) | ||
output_dir = sebs.utils.create_output(output_dir, preserve_out, verbose) | ||
ColoredPrinter.print(Colors.STATUS, sebs_client.logging, "Created experiment output at {}".format(output_dir)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will work for all calls you replaced in the CLI file sebs.py
. All other logging functionalities will not get colors.
We already have a logging base client. All other classes inherit from this class and later call self.logging.{logging_call}
. Perhaps
Perhaps we could implement it there, such that every call in every class in the project would go through your coloring scheme?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One possible implementation is to add to the logging base a @property
function called logging
that would return your colored wrapper instead of the original logger. This should seamlessly affect the entire project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have implemented all wrappers for logging, critical, error, warning, info and debug. Each of them are mapped to the corresponding appropriate colors.
sebs.py
Outdated
@@ -121,8 +122,8 @@ def parse_common_params( | |||
logging_filename = os.path.abspath(os.path.join(output_dir, output_file)) | |||
|
|||
sebs_client = sebs.SeBS(cache, output_dir, verbose, logging_filename) | |||
output_dir = sebs.utils.create_output(output_dir, preserve_out, verbose) | |||
sebs_client.logging.info("Created experiment output at {}".format(output_dir)) | |||
output_dir = sebs.utils.create_output(output_dir, preserve_out, verbose) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the trailing whitespace :-) Running tools/linting.py sebs
should help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reverted sebs.py
so there is no need to worry about the trailing whitespaces :D
sebs/color.py
Outdated
@@ -0,0 +1,17 @@ | |||
import click |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the approach to a dedicated class! What do you think about placing it in sebs/utils.py
instead of a separate file? It's quite small.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK :D
I have put it in the very bottom of sebs/utils.py
@lawrence910426 Thank you so much for your contribution! The CLI output looks much better already :-) I left a few comments on the review - most of them are super simple. I think that if we move the class to |
I have added a few more commits and fixed the problems mentioned. Thank you @mcopik again for your advising (^ ^/) |
sebs.py
Outdated
@@ -17,6 +17,7 @@ | |||
from sebs.utils import update_nested_dict, catch_interrupt | |||
from sebs.faas import System as FaaSSystem | |||
from sebs.faas.function import Trigger | |||
from sebs.color import Colors, ColoredPrinter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lawrence910426 This line may be unnecessary and may be forgotten to delete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch - this is now causing import error :)
sebs.py
Outdated
@@ -17,6 +17,7 @@ | |||
from sebs.utils import update_nested_dict, catch_interrupt | |||
from sebs.faas import System as FaaSSystem | |||
from sebs.faas.function import Trigger | |||
from sebs.color import Colors, ColoredPrinter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch - this is now causing import error :)
sebs/utils.py
Outdated
@@ -168,21 +171,26 @@ class LoggingBase: | |||
def __init__(self): | |||
uuid_name = str(uuid.uuid4())[0:4] | |||
if hasattr(self, "typename"): | |||
self.logging = logging.getLogger(f"{self.typename()}-{uuid_name}") | |||
self._logging = logging.getLogger(f"{self.typename()}-{uuid_name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also use the typename-uuid combination in the colored printer. It makes it much easier to debug experiments, especially the parallel ones.
Old
01:11:22,963 INFO AWS.HTTPTrigger-6c46: Invoke of function was successful
New, colored
[01:11:22.963650] Invoke of function was successful
The INFO
part we do not need :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sebs/utils.py
Outdated
|
||
@property | ||
def logging_handlers(self) -> LoggingHandlers: | ||
return self._logging_handlers | ||
|
||
@property | ||
def logging(self) -> logging.Logger: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The static return type is not correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I have it fixed.
sebs/utils.py
Outdated
|
||
def _print(self, message, color): | ||
timestamp = datetime.datetime.now().strftime("%H:%M:%S.%f") | ||
self.logging_instance.info(message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is the last remaining issue - right now, the output is duplicated because we have defined StreamHandler
above. I think your approach of printing to logging_instance
is correct because we want to also write to file. But we should now disable StreamHandler
and configure the ColorPrinter
with verbose
flag to decide if debug
should be printed or not,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have amended ColoredPrinter
to ColoredWrapper
, which would only propagate logging instructions to _logger
if filename
in LoggingHandler
is present. Moreover, StreamHandler
is removed, and its functions are implemented in ColoredWrapper
now.
@lawrence910426 Thanks for your hard work! I think it's almost there :) Please make sure to test to verify that the output is correct, such that we do not get duplicated output :) Looks really nice on my CLI! |
Hello @mcopik, I have these issues fixed :)
I have verified the output and it fits our expectations. Thank you again for your reviewing! This would surely made CLI more beautiful :) |
@lawrence910426 LGTM, thank you so much! This will make it much easier to catch warnings and errors, particularly in the verbose output mode :) |
Implemented issues #65.