# log.py -rw-r--r-- 1.3 KiB View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from pygments.lexer import RegexLexer, include
from pygments.token import *


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))', 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')
        ]
    }