Giter Site home page Giter Site logo

Comments (3)

borntyping avatar borntyping commented on August 16, 2024 1

An alternative that would work in the case of dictConfig would be to add a new parameter, though the code in Formatter.__init__ is already quite messy. It's probably easier to just copy the defaults into the dictConfig, as there aren't very many and they don't change:

logging:
  formatters:
    colored:
      (): "colorlog.ColoredFormatter"
      format: "..."
      log_colors:
        WARNING: "yellow"
        ERROR: "red"
        CRITICAL: "bold_red"

        INFO: "white"
        DEBUG: "light_blue"

from python-colorlog.

borntyping avatar borntyping commented on August 16, 2024

You can do easily this by merging the default_log_colors dictionary into a new one:

formatter = ColoredFormatter(
    ...
    log_colors={
        **colorlog.default_log_colors,
        'DEBUG': 'light_white',
    },
)

This will give you a ColoredFormatter that uses light_white for DEBUG records but still uses the default for other records.


Changing how the constructor works here would also mean it'd need a way to unset the defaults and would be a breaking change. For example, this wouldn't work the same way anymore:

formatter = ColoredFormatter(log_colors={'ERROR': 'light_white'})

At the moment that will make ERROR the only coloured records, instead of just changing the color of ERROR and using the default for other levels.

from python-colorlog.

espdev avatar espdev commented on August 16, 2024

@borntyping thanks for the response

Suggested approach unfortunately will not work with log configs. For logging configuration I use dictConfig from yaml file:

logging:
  formatters:
    colored:
      (): "colorlog.ColoredFormatter"
      format: "..."
      log_colors:
        INFO: "white"
        DEBUG: "light_blue"

In this case I cannot update log_colors from colorlog.default_log_colors in the config.

Changing how the constructor works here would also mean it'd need a way to unset the defaults and would be a breaking change. For example, this wouldn't work the same way anymore:

I agree. Suggested behavior by me is breaking changes. It's not good, so best left as is.

from python-colorlog.

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.