Code Monkey home page Code Monkey logo

Comments (13)

sfackler avatar sfackler commented on July 17, 2024 7

Progress! The encoder::Write trait has been extended with a set_style method, which can control the foreground and background colors as well as the foreground intensity of text it outputs. The console appender now colors text if attached to a tty/console. I've also added a new "highlight" formatter to the pattern syntax, which sets the color based on the log level. For example, the test crate now has the pattern {d} [{t}] {h({l})} {M}:{m}{n}, which produces output that looks like this when it runs:

capture

I copied the color selections from logback: intense red for error, red for warning, blue for info, and default for everything else.

I'd like to add a pattern formatter or group of them that lets you pick a specific style, but I'm not sure about the syntax right now.

from log4rs.

estk avatar estk commented on July 17, 2024 2

see #204 , its in progress but seems to be stalled

from log4rs.

owlmafia avatar owlmafia commented on July 17, 2024 1

Hi! I started using log4s and not seeing any colors in the terminal (I see them e.g. with pretty_env_logger). Do I have to enable it somewhere?

from log4rs.

Pr0gm4n avatar Pr0gm4n commented on July 17, 2024 1

@Creative-Difficulty you may want to try using the formatter {h} documented in the log4rs::encode::pattern, i.e., here.

As an example, you could use this in your yaml_config:

appenders:
  # An appender named "stdout" that writes to stdout
  stdout:
    kind: console
    target: stdout
    encoder:
      pattern: " {h({l:<5}} {M} > {m}{n}"

# Set the default logging level to "warn" and attach the "stdout" appender to the root
root:
  level: info
  appenders:
    - stdout

This should look somewhat similar to the output produced by the pretty_env_logger crate, although not with its neat alignment.

from log4rs.

sfackler avatar sfackler commented on July 17, 2024

Yep, definitely seems reasonable to implement! I will probably not have a ton of time to work on it, but if you were willing to that'd be great.

from log4rs.

ryantaylor avatar ryantaylor commented on July 17, 2024

I really like this library but I needed colorization, so I went ahead and hacked in super basic, super dirty functionality. No config or anything, just hard-coded colour values for different log levels. I wrote it for my own use until someone smarter than me found the time to implement a proper solution, but I figured I'd post it here in case it helps. If nobody else finds the time to work on this functionality I might look into cleaning up the code and doing it right.

ryantaylor@4ded253

from log4rs.

Nemikolh avatar Nemikolh commented on July 17, 2024

To be fair, I haven't found much time to work on this. Thanks for working on it !

As a comparison this is the default in log4js:

log4js

With your solution, it currently looks like this:
log4s

In my opinion, this is already a big improvement !
If you're willing to write a cleaner solution for it, feel free to do so.

from log4rs.

nicokoch avatar nicokoch commented on July 17, 2024

Is anyone still working on this? If not, I am willing to pick it up.

I will need some pointers on how one would configure this in the .toml file

from log4rs.

sfackler avatar sfackler commented on July 17, 2024

I don't think anyone's working on it right now. Logback's pattern syntax might be a place to look for configuration syntax inspiration: http://logback.qos.ch/manual/layouts.html#coloring

from log4rs.

sfackler avatar sfackler commented on July 17, 2024

I've started working on this.

from log4rs.

sfackler avatar sfackler commented on July 17, 2024

I've released v0.4.3 with color support. All that the pattern encoder supports right now is level-based styling. I've opened a new issue to figure out syntax for configuration of specific styles: #17

from log4rs.

OvermindDL1 avatar OvermindDL1 commented on July 17, 2024

What's keeping it stalled currently?

from log4rs.

Creative-Difficulty avatar Creative-Difficulty commented on July 17, 2024

Is there any progress at all @estk ?

from log4rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.