Skip to content

Instantly share code, notes, and snippets.

@bmarwell
Created October 16, 2014 11:04
Show Gist options
  • Save bmarwell/0ecda0a52b9cdf34829c to your computer and use it in GitHub Desktop.
Save bmarwell/0ecda0a52b9cdf34829c to your computer and use it in GitHub Desktop.
Use like this: 'zcat /opt/mcserver/bin/spigot/logs/2014-10-15-1.log.gz | tail -n 200 | pygmentize -l log' or just 'pygmentize /opt/mcserver/bin/spigot/logs/latest.log'.
from pygments.lexer import RegexLexer, bygroups
from pygments.token import *
__all__ = [ 'LogLexer' ]
class LogLexer(RegexLexer):
"""
Lexer for (minecraft) Log files.
"""
name = 'LOG'
aliases = ['log']
filenames = ['*.log']
tokens = {
'root': [
(r'^(\[)(\d\d)(:)(\d\d)(:)(\d\d)(\]\s)',
bygroups(Punctuation, Number.Integer, Punctuation, Number.Integer, Punctuation, Number.Integer, Punctuation)),
(r'(\[)(.*)(/)(.*)(\]:\s)',
bygroups(Punctuation, Name.Class, Punctuation, Name.Attribute, Punctuation)),
(r'(\[)(Server)(]\s)',
bygroups(Punctuation, Generic.Subheading, Punctuation)),
(r'.*\n', Text),
]
}
@bmarwell
Copy link
Author

To install, link or copy to your lexers directory, e.g. in Ubuntu to/usr/lib/python2.7/dist-packages/pygments/lexers/.

Then run sudo python _mapping.py.

You may use it now a described.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment