diff options
author | martijn@msi.localhost <martijn@msi.localhost> | 2019-05-02 16:05:35 +0200 |
---|---|---|
committer | Georg Brandl <g.brandl@fz-juelich.de> | 2019-12-09 12:32:53 +0100 |
commit | 64e9f90a6a91018ce9941c8b5a2362ff685c8fcf (patch) | |
tree | 7fd6d396aae83e6122220d8f09420a4886c21ffe /pygments/lexers/log.py | |
parent | 09ef9a63ff67790f14bf3201b7e548bffe602723 (diff) | |
download | pygments-git-64e9f90a6a91018ce9941c8b5a2362ff685c8fcf.tar.gz |
This commit adds a lexer for linux kernel logs as outputted by `dmesg`
It supports output from `dmesg`, in that case it highlights based on
keywords in the line
It can also highlight `dmesg -x` output. In that case it uses the
loglevels from the kernel to highlight the lines.
Diffstat (limited to 'pygments/lexers/log.py')
-rw-r--r-- | pygments/lexers/log.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/pygments/lexers/log.py b/pygments/lexers/log.py new file mode 100644 index 00000000..4f651bf2 --- /dev/null +++ b/pygments/lexers/log.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.log + ~~~~~~~~~~~~~~~~~~~~~ + + Lexers for various log file formats. + + :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.lexer import RegexLexer, include +from pygments.token import * + +__all__ = ['KernelLogLexer'] + + +class KernelLogLexer(RegexLexer): + name = 'Kernel log' + aliases = ['kmsg', 'dmesg'] + filenames = ['*.kmsg', '*.dmesg'] + + tokens = { + 'root': [ + (r'^(?=\[)', Text, 'unknown'), + (r'^([^:]+):debug\s*: (?=\[)', Text, 'debug'), + (r'^([^:]+):info\s*: (?=\[)', Text, 'info'), + (r'^([^:]+):warn\s*: (?=\[)', Text, 'warn'), + (r'^([^:]+):notice\s*: (?=\[)', Text, 'warn'), + (r'^([^:]+):err\s*: (?=\[)', Text, 'error'), + (r'^([^:]+):crit\s*: (?=\[)', Text, 'error'), + ], + 'unknown': [ + (r'^(?=.+(warning|notice|audit|deprecated))', Text, 'warn'), + (r'^(?=.+(error|critical|fail|Bug))', Text, 'error'), + (r'', Text, 'info'), + ], + 'base': [ + (r'\[[0-9\. ]+\] ', Number), + (r'(?<=\] ).+?:', Keyword), + (r'\n', Text, '#pop'), + ], + 'debug': [ + include('base'), + (r'.+\n', Text, '#pop') + ], + 'info': [ + include('base'), + (r'.+\n', Text, '#pop') + ], + 'warn': [ + include('base'), + (r'.+', Comment, '#pop') + ], + 'error': [ + include('base'), + (r'.+\n', Generic.Error, '#pop') + ] + } |