mozilla / janus-plugin-rs

Rust crate for wrapping the Janus C plugin API, so you can build Janus plugins in Rust.
Mozilla Public License 2.0
46 stars 18 forks source link

Fix colored log output #2

Closed ivanovaleksey closed 6 years ago

ivanovaleksey commented 6 years ago

Hi @mquander,

I noticed that log messages don't get colored.

After spending some time I found that it is mainly because of how we generate output string. We use push_str which requires &str as a parameter. So, we have to use & and dereference occurs on ColoredString instance.

Due to implementation of Deref for ColoredString only raw text gets returned (without any style attributes).

I tried to use write! and it worked. I also decided to change another push_str usages to write! for consistency.

What do you think?


Currently on master: image

With this patch: image

mqp commented 6 years ago

Thanks for catching this, I guess I must have broke it at some point. I have a test for log formatting, but not for log colorization -- might be nice to add one.

I like using write! instead of push_str and then push, that seems a little nicer.