Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples of changing colours? #110

Open
GanizaniSitara opened this issue Apr 17, 2022 · 1 comment
Open

Examples of changing colours? #110

GanizaniSitara opened this issue Apr 17, 2022 · 1 comment

Comments

@GanizaniSitara
Copy link

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= ?

@clayton13
Copy link

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")  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants