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

Console(log_path=False, log_time=False) doesn't work with logging module #72

Closed
keelung-yang opened this issue May 14, 2020 · 1 comment

Comments

@keelung-yang
Copy link

keelung-yang commented May 14, 2020

image

import sys
import logging

from rich.console import Console
from rich.logging import RichHandler

log_fmt = '%(asctime)s.%(msecs)03d %(levelname)s:\t%(message)s'
date_fmt='%H:%M:%S'
level = logging.INFO

console = Console(
    tab_size=4,
    #record=False,
    log_path=False,
    log_time=False,
    #log_time_format=date_fmt,
    #file=sys.stderr,
)

handle = RichHandler(
    level=level,
    console=console,
)

logging.basicConfig(
    level=level,
    format=log_fmt,
    datefmt=date_fmt,
    handlers=[handle],    # comment this line to disable rich
)

logging.info("Hello, World!")

And BTW, msecs is not supported in rich now? Thanks!

@willmcgugan
Copy link
Collaborator

Those parameters affect the Console.log method, the logging handler works differently, it takes the date format from the logging formatter and there is currently no option to not show the path.

If you want to configure logging more than what is offered, I'd suggest copying the handler code. It's a very simple class and you can modify it to your requirements.

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