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

Proposal: colors and styles #83

Closed
manio opened this issue Oct 25, 2021 · 5 comments
Closed

Proposal: colors and styles #83

manio opened this issue Oct 25, 2021 · 5 comments

Comments

@manio
Copy link
Contributor

manio commented Oct 25, 2021

Hi!
I really like use your simplelog as my main logger for projects :)
I am now experimenting with adding support for bold/italic and colors in my log messages.
I am not aware of this with the simplelog (correct me if I am wrong), so I am using an ansi_term crate for this.

The downsides of this approach:

  1. A plenty of additional calls are needed, eg to make a text bold green I have to call:
    Style::new().bold().fg(Green).paint(err.to_string())
  2. the writelogger is not aware of the control characters and put it "as is" in the files - making it less readable (this is currently also a problem when using some other crates which is using a colored text, eg rocket).

I want to ask what is your opinion to have in simplelog something similar as in paris, ie parser for the following:
log.info("<blue><on-bright-red> This text is blue on a bright red background</> it's a pain");
I am not sure if the above parsing is even possible when using error!, info! macros from rust...?

Is it in a scope of this project?

@Drakulix
Copy link
Owner

Drakulix commented Oct 25, 2021

So what I think would be in scope is some kind of filter for control sequences at least.
Maybe an additional wrapping-logger could be provided, that does remove control sequences and can then be used in conjunction with e.g. WriteLogger.

paris looks like a really nice crate from an api-perspective. But I am not sure, how much code this would add to simplelog and if it would not be better to implement a new crate similar to paris, but with log support. (Essentially just proxy-ing the log-macros.)

That said, I would definitely consider having a tight integration with a crate like that in simplelog. I am just not sure, if I want to maintain all that parsing code myself.

@manio
Copy link
Contributor Author

manio commented Oct 25, 2021

I see, thank you for fast answer. Because this is not a issue "per se" so I am closing it for now... will reopen when necessary.

@manio manio closed this as completed Oct 25, 2021
@manio
Copy link
Contributor Author

manio commented Oct 25, 2021

Just for future reference...
I did it like this:

use paris::formatter::colorize_string;
//standard simplelog initialize
let t = colorize_string("<blue><on-bright-red> This text is blue on a bright red background</> it's a pain");
info!("{}", t);
//or:
warn!("{}", colorize_string("<b><green>test string"));

I will now search how can I wrap it in some macro (proxy as you mention) to be able to use it like before using just info!, warn!, etc

@Drakulix
Copy link
Owner

If you manage to do that, I would accept those macros (assuming they would be rather simple) in simplelog behind a (by default disabled) optional paris feature.

@manio
Copy link
Contributor Author

manio commented Oct 25, 2021

Great, added a PR #84.
Let's move discussion there...

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

No branches or pull requests

2 participants