on master help sign in
Merge pull request #1606 from sharkdp/syslog

Improve Syslog and general log file highlighting

commit2904f24ea803ce3fd51cb4080949c8d53e14d06e authorDavid Peter <sharkdp@users.noreply.github.com> dateWed 12 May 2021, 22:22 (5 years ago) parent91a347b5db3c93
10 files changed+224−5
.gitmodules−4 CHANGELOG.md+1 assets/patches/Monokai-Extended.tmTheme.patch+18 assets/syntaxes/02_Extra/Syslog−1 assets/syntaxes/02_Extra/log.sublime-syntax+116 assets/syntaxes/02_Extra/syslog.sublime-syntax+63 tests/syntax-tests/highlighted/Log/example.log+2 tests/syntax-tests/highlighted/Syslog/example.syslog+11 tests/syntax-tests/source/Log/example.log+2 tests/syntax-tests/source/Syslog/example.syslog+11
.gitmodules−4
@@ -94,10 +94,6 @@
9494[submodule "assets/syntaxes/Assembly (ARM)"]
9595 path = assets/syntaxes/02_Extra/Assembly (ARM)
9696 url = https://github.com/tvi/Sublime-ARM-Assembly
97−[submodule "assets/syntaxes/syslog-syntax"]
98− path = assets/syntaxes/02_Extra/Syslog
99− url = https://github.com/caos21/syslog-syntax.git
100− branch = master
10197[submodule "assets/syntaxes/protobuf-syntax-highlighting"]
10298 path = assets/syntaxes/02_Extra/Protobuf
10399 url = https://github.com/VcamX/protobuf-syntax-highlighting.git
CHANGELOG.md+1
@@ -13,6 +13,7 @@
1313
1414## Syntaxes
1515
16+- Improved the Syslog syntax highlighting, see #1606 (@keith-hall)
1617- Replaced "Advanced CSV" with a custom CSV syntax definition written especially for `bat`; see #1574 (@keith-hall)
1718
1819## New themes
assets/patches/Monokai-Extended.tmTheme.patch+18
@@ -16,3 +16,21 @@ index 9c2aa3e..180cbbf 100644
1616 </dict>
1717 </dict>
1818 <dict>
19+@@ -1027,7 +1027,7 @@
20+ <key>name</key>
21+ <string>Invalid</string>
22+ <key>scope</key>
23+- <string>invalid</string>
24++ <string>invalid, markup.error</string>
25+ <key>settings</key>
26+ <dict>
27+ <key>background</key>
28+@@ -1042,7 +1042,7 @@
29+ <key>name</key>
30+ <string>Invalid deprecated</string>
31+ <key>scope</key>
32+- <string>invalid.deprecated</string>
33++ <string>invalid.deprecated, markup.warning</string>
34+ <key>settings</key>
35+ <dict>
36+ <key>background</key>
assets/syntaxes/02_Extra/Syslogdeleted−1

Submodule changed.

assets/syntaxes/02_Extra/log.sublime-syntaxnew file+116
@@ -0,0 +1,116 @@
1+%YAML 1.2
2+---
3+# See http://www.sublimetext.com/docs/3/syntax.html
4+file_extensions:
5+ - log
6+scope: text.log
7+variables:
8+ ipv4_part: (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
9+contexts:
10+ main:
11+ - match: (\w+)(=)
12+ captures:
13+ 1: variable.parameter.log
14+ 2: keyword.operator.assignment.log
15+ - match: (')([^']*)(')
16+ scope: string.quoted.single.log
17+ captures:
18+ 1: punctuation.definition.string.begin.log
19+ 3: punctuation.definition.string.end.log
20+ - match: (")([^"]*)(")
21+ scope: string.quoted.double.log
22+ captures:
23+ 1: punctuation.definition.string.begin.log
24+ 3: punctuation.definition.string.end.log
25+ - include: dates
26+ - include: ip_addresses
27+ - include: numbers
28+ - match: \b(?i:fail(?:ure|ed)?|error|exception)\b
29+ scope: markup.error.log
30+ - match: \b(?i:warn(?:ing)?)\b
31+ scope: markup.warning.log
32+ #- include: scope:text.html.markdown#autolink-inet
33+ - match: \b\w+:/{2,3}
34+ scope: markup.underline.link.scheme.log
35+ push: url-host
36+ dates:
37+ - match: \b\d{4}-\d{2}-\d{2}\b
38+ scope: meta.date.log meta.number.integer.decimal.log constant.numeric.value.log
39+ - match: \b\d{4}/\d{2}/\d{2}\b
40+ scope: meta.date.log meta.number.integer.decimal.log constant.numeric.value.log
41+ - match: \b(?:[01]\d|2[0-3]):(?:[0-5]\d):(?:[0-5]\d)(?:(\.)\d{3})?\b
42+ scope: meta.time.log meta.number.integer.decimal.log constant.numeric.value.log
43+ captures:
44+ 1: punctuation.separator.decimal.log
45+ ip_addresses:
46+ - match: \b(?=(?:{{ipv4_part}}\.){3}{{ipv4_part}}\b)
47+ push:
48+ - meta_scope: meta.ipaddress.v4.log meta.number.integer.decimal.log
49+ - match: \d+
50+ scope: constant.numeric.value.log
51+ - match: \.
52+ scope: punctuation.separator.sequence.log
53+ - match: ''
54+ pop: true
55+ - match: (?=(?:\h{0,4}:){2,6}\h{1,4}\b)
56+ push:
57+ - meta_scope: meta.ipaddress.v6.log meta.number.integer.hexadecimal.log
58+ - match: \h{1,4}
59+ scope: constant.numeric.value.log
60+ - match: ':'
61+ scope: punctuation.separator.sequence.log
62+ - match: ''
63+ pop: true
64+ numbers:
65+ - match: \b(0x)(\h+)(?:(\.)(\h+))?\b
66+ scope: meta.number.float.hexadecimal.log
67+ captures:
68+ 1: constant.numeric.base.log
69+ 2: constant.numeric.value.log
70+ 3: constant.numeric.value.log punctuation.separator.decimal.log
71+ 4: constant.numeric.value.log
72+ - match: \b\d+(\.)\d+\b
73+ scope: meta.number.float.log constant.numeric.value.log
74+ captures:
75+ 1: punctuation.separator.decimal.log
76+ - match: \b\d+\b
77+ scope: meta.number.integer.log constant.numeric.value.log
78+ url-host:
79+ - meta_content_scope: markup.underline.link.host.log
80+ - match: \[
81+ scope: punctuation.section.brackets.begin.log
82+ push:
83+ - match: \]
84+ scope: punctuation.section.brackets.end.log
85+ pop: true
86+ - include: ip_addresses
87+ - match: '[^:/\s]+'
88+ - match: ''
89+ set: url-after-host
90+ url-after-host:
91+ - match: (:)(\d+)
92+ scope: markup.underline.link.port.log
93+ captures:
94+ 1: punctuation.separator.mapping.port.log
95+ 2: constant.numeric.value.log
96+ #- include: scope:text.html.markdown#url-escaped-chars
97+ - match: (%)\h{2}
98+ scope: markup.underline.link.path.log constant.character.escape.url.log
99+ captures:
100+ 1: punctuation.definition.escape.log
101+ # After a valid domain, zero or more non-space non-< characters may follow
102+ - match: (?=[?!.,:*_~]*[\s<]) # Trailing punctuation (specifically, ?, !, ., ,, :, *, _, and ~) will not be considered part of the autolink, though they may be included in the interior of the link
103+ pop: true
104+ - match: \( # When an autolink ends in ), we scan the entire autolink for the total number of parentheses. If there is a greater number of closing parentheses than opening ones, we don’t consider the last character part of the autolink, in order to facilitate including an autolink inside a parenthesis
105+ push:
106+ - meta_scope: markup.underline.link.path.log
107+ - match: (?=[?!.,:*_~]*[\s<])
108+ pop: true
109+ - match: \)
110+ pop: true
111+ - match: (?=\)[?!.,:*_~]*[\s<])
112+ pop: true
113+ - match: '[^?!.,:*_~\s<&()%]+|\S'
114+ scope: markup.underline.link.path.log
115+ - match: ''
116+ pop: true
assets/syntaxes/02_Extra/syslog.sublime-syntaxnew file+63
@@ -0,0 +1,63 @@
1+%YAML 1.2
2+---
3+# http://www.sublimetext.com/docs/3/syntax.html
4+name: syslog
5+file_extensions:
6+ - syslog
7+scope: text.log.syslog
8+contexts:
9+ main:
10+ - match: ^(\w+\s+\d+)\s+(\d{2}:\d{2}:\d{2})
11+ scope: meta.datetime.syslog constant.numeric.syslog
12+ captures:
13+ 1: meta.date.syslog
14+ 2: meta.time.syslog
15+ push: loghost
16+ - match: ^
17+ push: text
18+ loghost:
19+ - match: '[\w-]+'
20+ scope: entity.other.attribute-name.loghost.syslog
21+ set: process
22+ process:
23+ - match: ([\w-]+)(?:(\[)(\d+)(\]))?(:)
24+ captures:
25+ 1: support.function.process.syslog
26+ 2: punctuation.separator.pid.begin.syslog
27+ 3: meta.pid.syslog meta.number.integer.syslog constant.numeric.value.syslog
28+ 4: punctuation.separator.pid.end.syslog
29+ 5: punctuation.separator.mapping.syslog
30+ set: structured-data
31+ structured-data:
32+ - match: '\['
33+ scope: punctuation.section.mapping.begin.syslog
34+ push:
35+ - match: \]
36+ scope: punctuation.section.mapping.end.syslog
37+ pop: true
38+ - match: \w+
39+ scope: variable.parameter.syslog
40+ - match: =
41+ scope: keyword.operator.assignment.syslog
42+ push:
43+ - match: '[^\s\]]+'
44+ scope: constant.other.syslog
45+ pop: true
46+ - match: (?=\])
47+ pop: true
48+ - match: (?=\S)
49+ set: text
50+ text:
51+ - match: $
52+ pop: true
53+ - match: '<\w+>'
54+ scope: constant.language.syslog
55+ - match: \b(CMD)\b\s+(\()
56+ captures:
57+ 1: entity.name.label.syslog
58+ 2: punctuation.section.block.begin.syslog
59+ embed: scope:source.shell.bash
60+ escape: \)$
61+ escape_captures:
62+ 0: punctuation.section.block.end.syslog
63+ - include: scope:text.log
tests/syntax-tests/highlighted/Log/example.lognew file+2
@@ -0,0 +1,2 @@
1+2021-03-06 23:22:21.392 https://[2001:db8:4006:812::200e]:8080/path/the%20page.html
2+2021-03-06 23:22:21 https://example.com:8080/path/the%20page(with_parens).html
tests/syntax-tests/highlighted/Syslog/example.syslognew file+11
@@ -0,0 +1,11 @@
1+Apr 4 00:00:01 hostname-here systemd[1]: logrotate.service: Succeeded.
2+Apr 4 00:00:01 hostname-here systemd[1]: Finished Rotate log files.
3+Apr 4 00:00:01 hostname-here colord[920]: failed to get session [pid 137485]: No data available
4+Apr 4 00:00:21 hostname-here kernel: [55604.908232] audit: type=1400 audit(1617483621.094:28): apparmor="DENIED" operation="capable" profile="/usr/sbin/cups-browsed" pid=59311 comm="cups-browsed" capability=23 capname="sys_nice"
5+Apr 4 00:01:38 hostname-here systemd-resolved[721]: Server returned error NXDOMAIN, mitigating potential DNS violation DVE-2018-0001, retrying transaction with reduced feature level UDP.
6+Apr 4 00:04:46 hostname-here ntpd[952]: Soliciting pool server 255.76.59.37
7+Apr 4 00:05:21 hostname-here ntpd[952]: ::1 local addr 0:0:0:0:0:0:0:1 -> <null>
8+Apr 4 00:06:29 hostname-here ntpd[952]: receive: Unexpected origin timestamp 0xe414a8d1.82e825f5 does not match aorg 0xe414a8d5.82c50d8c from server@127.0.0.1 xmt 0xe414a8d1.e671d7c4
9+Apr 4 09:30:01 hostname-here CRON[89278]: (root) CMD ([ -x /etc/init.d/anacron ] && if [ ! -d /run/systemd/system ]; then /usr/sbin/invoke-rc.d anacron start >/dev/null; fi)
10+Apr 4 16:32:07 hostname-here NetworkManager[740]: <info> [1617629527.1101] manager: NetworkManager state is now CONNECTED_GLOBAL
11+Apr 4 22:00:45 hostname-here dbus-daemon[1094]: [session uid=1000 pid=1094] Successfully activated service 'io.github.celluloid_player.Celluloid'
tests/syntax-tests/source/Log/example.lognew file+2
@@ -0,0 +1,2 @@
1+2021-03-06 23:22:21.392 https://[2001:db8:4006:812::200e]:8080/path/the%20page.html
2+2021-03-06 23:22:21 https://example.com:8080/path/the%20page(with_parens).html
tests/syntax-tests/source/Syslog/example.syslognew file+11
@@ -0,0 +1,11 @@
1+Apr 4 00:00:01 hostname-here systemd[1]: logrotate.service: Succeeded.
2+Apr 4 00:00:01 hostname-here systemd[1]: Finished Rotate log files.
3+Apr 4 00:00:01 hostname-here colord[920]: failed to get session [pid 137485]: No data available
4+Apr 4 00:00:21 hostname-here kernel: [55604.908232] audit: type=1400 audit(1617483621.094:28): apparmor="DENIED" operation="capable" profile="/usr/sbin/cups-browsed" pid=59311 comm="cups-browsed" capability=23 capname="sys_nice"
5+Apr 4 00:01:38 hostname-here systemd-resolved[721]: Server returned error NXDOMAIN, mitigating potential DNS violation DVE-2018-0001, retrying transaction with reduced feature level UDP.
6+Apr 4 00:04:46 hostname-here ntpd[952]: Soliciting pool server 255.76.59.37
7+Apr 4 00:05:21 hostname-here ntpd[952]: ::1 local addr 0:0:0:0:0:0:0:1 -> <null>
8+Apr 4 00:06:29 hostname-here ntpd[952]: receive: Unexpected origin timestamp 0xe414a8d1.82e825f5 does not match aorg 0xe414a8d5.82c50d8c from server@127.0.0.1 xmt 0xe414a8d1.e671d7c4
9+Apr 4 09:30:01 hostname-here CRON[89278]: (root) CMD ([ -x /etc/init.d/anacron ] && if [ ! -d /run/systemd/system ]; then /usr/sbin/invoke-rc.d anacron start >/dev/null; fi)
10+Apr 4 16:32:07 hostname-here NetworkManager[740]: <info> [1617629527.1101] manager: NetworkManager state is now CONNECTED_GLOBAL
11+Apr 4 22:00:45 hostname-here dbus-daemon[1094]: [session uid=1000 pid=1094] Successfully activated service 'io.github.celluloid_player.Celluloid'