Viewing log messages with Emacs

937 Views Asked by At

After running the Python code

import logging

logging.basicConfig(filename='./output.log',
                    level=logging.DEBUG,
                    format=('%(asctime)s\t%(levelname)s --'
                            ' %(processName)s '
                            '%(filename)s:%(lineno)s -- '
                            '%(message)s'))
logging.debug('This is a debug message')
logging.info('This is an info message')
logging.warning('This is a warning message')
logging.error('This is an error message')
logging.critical('This is a critical message')

I get in the log file output.log the following content.

2019-09-04 14:24:32,268 DEBUG -- MainProcess experiment.py:9 -- This is a debug message
2019-09-04 14:24:32,268 INFO -- MainProcess experiment.py:10 -- This is an info message
2019-09-04 14:24:32,268 WARNING -- MainProcess experiment.py:11 -- This is a warning message
2019-09-04 14:24:32,269 ERROR -- MainProcess experiment.py:12 -- This is an error message
2019-09-04 14:24:32,269 CRITICAL -- MainProcess experiment.py:13 -- This is a critical message

When I read the file with Emacs 26.2 started using the following ~/.emacs

(set-foreground-color "white")
(set-background-color "black")
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)
(require 'logview)

I end up with a tedious monochromatic image

logging output is monochromatic

which makes it hard to scan for errors/warnings, and to scan the elements of each log message.

I understand that there is no such a thing as a standard ".log" format, or at least multiple formats competing for the .log extension. Still, can you suggest some elisp package along with perhaps a specific extension that will distinguish through font-lock the log levels as well as the elements of each log message?

0

There are 0 best solutions below