NRLMMD-GEOIPS / geoips

Main Geolocated Information Processing System code base with basic functionality enabled.
https://nrlmmd-geoips.github.io/geoips/
Other
13 stars 10 forks source link

Consider adding Colorama Functionality to Logging Utility Functions #476

Open evrose54 opened 2 months ago

evrose54 commented 2 months ago

Requested Update

Description

GeoIPS currently has a logging utility called log_with_emphasis, which logs text in an emphasized manner. An example of what the function would output is shown below. This is a nice utility to have, but could be expanded on more. It would be nice to have a utility function that makes use of Colorama's colored text / background to emphasize certain parts of the log output, highlight warnings, etc.

In [3]: log_with_emphasis(print, *["howdy", "what's up", "this is a very long string"])
********************************
** howdy                      **
** what's up                  **
** this is a very long string **
********************************

An example of a colored utility function could look something like this:

color_log_output(print_func, *messages, **kwargs)

Where kwargs is a dictionary of keyword arguments. This dictionary would look something like this:

{
    "title": <title_text>,
    "footer": <footer_text>,
    "background_color": <colorama_color_name>,
    "title_color": <colorama_color_name>,
    "message_color": <colorama_color_name>,
    "footer_color": <colorama_color_name>,
    "font_size": <font_size_int>,
    "font": <font_name>,
}

An example of how this function could be called would look like this:

color_kwargs = {
    "title": "Colored Log Output",
    "footer": "End of Colored Log Output",
    "title_color": "green",
    "message_color": "cyan",
    "footer_color": "red",
}
color_log_output(print, *["Please color me cyan", "not blue", "or some ugly brown color."], **color_kwargs)

If none of those kwargs were to be specified, we'd just default to a certain argument. This could ultimately replace the log_with_emphasis function if we wanted, or we could add a new utility function that would implement what I specified above.

Background and Motivation

This stems from discussions we've had about the log_with_emphasis function. See #377.

Alternative Solutions

Leave the code as is

biosafetylvl5 commented 2 months ago

Color! All the way 🔴 🟢 🔵

Instead of implementing something like

color_log_output(print_func, *messages, **kwargs)

could we use something like termcolor, rich or blessings?

eg. we could do this: log.info(colored("message", "red")) (using syntax from termcolor) or even

log_with_emphasis(LOG.info, *messages, color_func=color("red"))

This would mean we don't have to worry about cross-platform compatibility, maintaining the code, etc. (all the usual benefits of using open source external code).

It also allows us to do fun stuff like:

formatting

without having to write extra code to support it.