Comments (3)
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.
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.
@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)
- No module named 'colorlog' HOT 1
- v4.8.0 - ColoredRecord does not set asctime property. HOT 2
- 5.0.0: test suite warnings HOT 2
- 'bold' option is not working HOT 1
- Typing information is missing on import. HOT 2
- ModuleNotFoundError: No module named 'colorlog' HOT 1
- Purple - PowerShell HOT 1
- hope add predefined level such as colorlog.ERROR colorlog.DEBUG and so on HOT 1
- [Bug] colorlog.basicConfig() doesn't seems to work when upgrading from v5 to v6 HOT 3
- colorlog introduces "[1m[0m"-like entries in logs running on argo workflows HOT 2
- Logging is sometimes duplicated without color HOT 5
- How to make `print()` statement output colorful?
- Doesn't support defaults HOT 1
- Document `light_*` colors? HOT 4
- Failed to add color to log HOT 4
- Docu like ReadTheDocs / Offering a objects.inv HOT 1
- Duplicative stream definition required due to design choice made in #64 HOT 1
- support *stacklevel* argument HOT 3
- colorlog.basicConfig does not accept '{' style HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-colorlog.