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 | |
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')
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/log.py | 59 |
2 files changed, 60 insertions, 0 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 1ed7140d..8a09ea2b 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -233,6 +233,7 @@ LEXERS = { 'JuttleLexer': ('pygments.lexers.javascript', 'Juttle', ('juttle', 'juttle'), ('*.juttle',), ('application/juttle', 'application/x-juttle', 'text/x-juttle', 'text/juttle')), 'KalLexer': ('pygments.lexers.javascript', 'Kal', ('kal',), ('*.kal',), ('text/kal', 'application/kal')), 'KconfigLexer': ('pygments.lexers.configs', 'Kconfig', ('kconfig', 'menuconfig', 'linux-config', 'kernel-config'), ('Kconfig', '*Config.in*', 'external.in*', 'standard-modules.in'), ('text/x-kconfig',)), + 'KernelLogLexer': ('pygments.lexers.log', 'Kernel log', ('kmsg', 'dmesg'), ('*.kmsg', '*.dmesg'), ()), 'KokaLexer': ('pygments.lexers.haskell', 'Koka', ('koka',), ('*.kk', '*.kki'), ('text/x-koka',)), 'KotlinLexer': ('pygments.lexers.jvm', 'Kotlin', ('kotlin',), ('*.kt',), ('text/x-kotlin',)), 'LSLLexer': ('pygments.lexers.scripting', 'LSL', ('lsl',), ('*.lsl',), ('text/x-lsl',)), 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') + ] + } |