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

Levels Colorization #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

yousifnimah
Copy link

Levels Colorization

This pull request adds colorization support for log levels in the logging package. Each log level is assigned a specific color based on its string representation, providing improved visual distinction for log entries.

Changes Made

  • Added colorization support for log levels in the ColorizeLevel function.
  • Created custom color types for each log level (DefaultColor, DebugColor, InfoColor, etc.).
  • Implemented the Color interface and added corresponding methods to retrieve the ANSI escape codes for each color.
  • Updated the PrintColor function to set the appropriate color for the log level and print it.

Usage

To use the colorized log levels, simply call the ColorizeLevel function and pass the log level as an argument. For example:

ColorizeLevel(DEBUG)

Example of output:
image

@coveralls
Copy link

Coverage Status

coverage: 93.464% (-0.3%) from 93.807% when pulling 3678423 on yousifnimah:master into d2677a2 on go-playground:master.

Copy link
Contributor

@deankarn deankarn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First off, TY for taking the time for making a PR to improve this library.

Unfortunately I won't be able to merge this. This change assumes that all handlers may be interesting in coloured output, but in reality almost that's exclusive to logging within the terminal.

Color or other options like this should be the responsibility of each handler itself to keep the logging library agnostic. Also I'm not sure I'm sold on the whole line being coloured vs the key information(where you want your eye to be drawn to).

I used to have a coloured output option logger in v7 of this library here. I'd be willing to re-add this alongside the existing json logger to the built-in handlers again(with a few minor tweaks) and optional colour based on terminal detection in the default logger :)

The only issue is that I'm very busy at the moment and won't be able to find the time for at least 3 weeks, maybe more.

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

Successfully merging this pull request may close these issues.

3 participants