Skip to content
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

Change kedro log messages to be more rich #1514

Closed
Tracked by #1461
antonymilne opened this issue May 6, 2022 · 0 comments · Fixed by #1663
Closed
Tracked by #1461

Change kedro log messages to be more rich #1514

antonymilne opened this issue May 6, 2022 · 0 comments · Fixed by #1663
Assignees

Comments

@antonymilne
Copy link
Contributor

antonymilne commented May 6, 2022

🥳 FUN TICKET 🥳 Prerequisites: #1512. Based off point 3 in #1464

Let's take advantage of the nice formatting we can do with rich and make Kedro's log messages prettier.

  • replace backticks (`) in all log messages with quote marks (can be single or double). This will be a lot of very small changes!
  • edit log messages to be clearer and prettier using console markup. Note:
    • let's not go too crazy here. Try and restrict to sensible styles so that we have a somewhat unified appearance that we know works on a variety of background colours. Take inspiration from the styles in the picture below (e.g. [bold bright_green] is used but won't appear much by default so it's a good candidate to use)
    • any log messages you add markup to will need to have extra={"markup": True} in the logging call as explained in the rich docs. If we end up adding markup to loads of logging calls it might be easier to alter the kedro logger (not the root one!!) in framework logging.yml to set markup: true
    • start with the logging messages that are most important/frequently seen during a kedro run. Check point 3 in The road to introducing rich into Kedro natively #1464 and the associated code by @datajoely for what the "highest impact" logging calls are and some suggested ways to style them. But feel free to add markup to any other logging calls throughout kedro too - the sky's the limit here! 🚀
    • similarly feel free to go beyond just adding markup and change the wording/style of brackets/arrows/etc. in the log messages if you think they can be improved, as @datajoely did.

Useful context: how rich formatting works

We are using the RichHandler for logging. By default this highlights messages automatically according to the ReprHighlighter. Here's how different things get highlighted (generated using python -m rich.default_styles):
image

Here's an example of what this means in practice:
image

e.g. the numbers are styled according to repr.number. Strings are styled according to repr.str. The definition of what is interpreted as a string is given by this regex, which is complicated but the outcome is that stuff in ' or " gets highlighted as a string, but the backtick ` has no special meaning.

In the past we've tended to use backticks to highlight things like dataset and node names. To get these nicely highlighted there's a few options:

  1. convert where we use backticks to quote marks so they get automatically highlighted
  2. make a custom highlighter which extends ReprHighlighter and adds a regex to specially format things enclosed in backticks
  3. instead of using backticks, come up with something our own more semantic tag like [dataset] and [node] and define a custom theme

Overall 2 and 3 would be kind of cool but seem like big overkill here, hence going for option 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants