Mar-21-2024, 10:15 AM
Hi,
I am trying to use
Originally I had the following setup for my logging to file which works fine:
Thanks for any advice you can give.
I am trying to use
rich.logging to have more readable logs. Can this be done? As you will see I'm not doing well! ;)Originally I had the following setup for my logging to file which works fine:
logging.basicConfig(
format='%(asctime)s [%(levelname)s] [%(name)s] - %(message)s (%(filename)s:%(lineno)d)',
level='INFO',
datefmt='%Y-%m-%d %H:%M:%S',
filename='/tmp/foo.log')
logger = logging.getLogger('Main')I tried a few variants of the following:logging.basicConfig(
format='%(asctime)s [%(levelname)s] [%(name)s] - %(message)s (%(filename)s:%(lineno)d)',
level='INFO',
datefmt='%Y-%m-%d %H:%M:%S',
handlers=[
logging.FileHandler('/tmp/foo.log', mode='a'),
RichHandler(rich_tracebacks=True, console=None,show_path=True)])
logger = logging.getLogger('Main')
logger.info('info log')What the above seems to do is output the following to the terminal:Output:info log
INFO info log <stdin>:3
[03/21/24 11:00:48] INFO info log <stdin>:3
[03/21/24 11:00:48] INFO info log <stdin>:3
[03/21/24 11:00:48] INFO info log <stdin>:3and the following to the foo.log logfile:Output:info log
info log
info log
info log
info logThe formatting of the log line is wrong, I output to terminal and log file rather than just the log file and the log file does not take the format into account. I think it's clear I need help. I could not find documentation that allowed me to use rich.logging to output colour and formatting to a log file.Thanks for any advice you can give.
