python-coloredlogs
python-coloredlogs copied to clipboard
Examples of changing colours?
Are there any examples of changing colours? The official documentation seems to show everything as environment variables. How do you do this in code? Is it passed as a parameter to the install function similarly to fmt= ?
Yep! Fields are passed into level_styles and field_styles.
The color fields seem to be directly driven from: humanfriendly.terminal.ansi_style
Can likely copy/update the existing dictionary from coloredlogs. DEFAULT_LEVEL_STYLES as well.
import coloredlogs
import logging
styles = {
'trace': {
'color': 'black',
'bright': True
},
'debug': {
'color': 'white'
},
'info': {
'color': 'green'
},
'warning': {
'color': 'yellow'
},
'error': {
'color': 'red'
},
'critical': {
'bold': True,
'color': 'red'
}
}
coloredlogs.install(level=logging.INFO, fmt='%(levelname)-8.8s [%(filename)s:%(lineno)s %(funcName)20s()] %(message)s',
level_styles=styles)
logger = logging.getLogger(__name__)
logger.info("hello world")
logger.critical("hello world")