Skip to content

Commit 2bc6475

Browse files
Added support for Generic log files (#2796)
1 parent 1a2347a commit 2bc6475

28 files changed

+4071
-2
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+4
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,10 @@
733733
"title": "LLVM IR",
734734
"owner": "porglezomp"
735735
},
736+
"log": {
737+
"title": "Log file",
738+
"owner": "RunDevelopment"
739+
},
736740
"lolcode": {
737741
"title": "LOLCODE",
738742
"owner": "Golmote"

components/prism-log.js

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// This is a language definition for generic log files.
2+
// Since there is no one log format, this language definition has to support all formats to some degree.
3+
//
4+
// Based on https://github.com/MTDL9/vim-log-highlighting
5+
6+
Prism.languages.log = {
7+
'string': {
8+
// Single-quoted strings must not be confused with plain text. E.g. Can't isn't Susan's Chris' toy
9+
pattern: /"(?:[^"\\\r\n]|\\.)*"|'(?![st] | \w)(?:[^'\\\r\n]|\\.)*'/,
10+
greedy: true,
11+
},
12+
13+
'level': [
14+
{
15+
pattern: /\b(?:ALERT|CRIT|CRITICAL|EMERG|EMERGENCY|ERR|ERROR|FAILURE|FATAL|SEVERE)\b/,
16+
alias: ['error', 'important']
17+
},
18+
{
19+
pattern: /\b(?:WARN|WARNING)\b/,
20+
alias: ['warning', 'important']
21+
},
22+
{
23+
pattern: /\b(?:DISPLAY|INFO|NOTICE|STATUS)\b/,
24+
alias: ['info', 'keyword']
25+
},
26+
{
27+
pattern: /\b(?:DEBUG|FINE)\b/,
28+
alias: ['debug', 'keyword']
29+
},
30+
{
31+
pattern: /\b(?:FINER|FINEST|TRACE|VERBOSE)\b/,
32+
alias: ['trace', 'comment']
33+
}
34+
],
35+
36+
'property': {
37+
pattern: /((?:^|[\]|])[ \t]*)[a-z_](?:[\w-]|\b\/\b)*(?:[. ]\(?\w(?:[\w-]|\b\/\b)*\)?)*:(?=\s)/im,
38+
lookbehind: true
39+
},
40+
41+
'separator': {
42+
pattern: /(^|[^-+])-{3,}|={3,}|\*{3,}|- - /m,
43+
lookbehind: true,
44+
alias: 'comment'
45+
},
46+
47+
'url': /\b(?:https?|ftp|file):\/\/[^\s|,;'"]*[^\s|,;'">.]/,
48+
'email': {
49+
pattern: /(^|\s)[-\w+.]+@[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+(?=\s)/,
50+
lookbehind: true,
51+
alias: 'url'
52+
},
53+
54+
'ip-address': {
55+
pattern: /\b(?:\d{1,3}(?:\.\d{1,3}){3})\b/i,
56+
alias: 'constant'
57+
},
58+
'mac-address': {
59+
pattern: /\b[a-f0-9]{2}(?::[a-f0-9]{2}){5}\b/i,
60+
alias: 'constant'
61+
},
62+
'domain': {
63+
pattern: /(^|\s)[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)*\.[a-z][a-z0-9-]+(?=\s)/,
64+
lookbehind: true,
65+
alias: 'constant'
66+
},
67+
68+
'uuid': {
69+
pattern: /\b\w{8}-\w{4}-\w{4}-\w{4}-\w{12}\b/,
70+
alias: 'constant'
71+
},
72+
'hash': {
73+
pattern: /\b(?:[a-f0-9]{32}){1,2}\b/i,
74+
alias: 'constant'
75+
},
76+
77+
'file-path': {
78+
pattern: /\b[a-z]:[\\/][^\s|,;:(){}\[\]"']+|(^|[\s:\[\](>|])\.{0,2}\/\w[^\s|,;:(){}\[\]"']*/i,
79+
lookbehind: true,
80+
greedy: true,
81+
alias: 'string'
82+
},
83+
84+
'date': {
85+
pattern: RegExp(
86+
/\b\d{4}[-/]\d{2}[-/]\d{2}T(?=\d{1,2}:)/.source +
87+
'|' +
88+
/\b\d{1,4}[-/ ](?:\d{1,2}|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[-/ ]\d{2,4}T?\b/.source +
89+
'|' +
90+
/\b(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)(?:\s{1,2}(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))?|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s{1,2}\d{1,2}\b/.source,
91+
'i'
92+
),
93+
alias: 'number'
94+
},
95+
'time': {
96+
pattern: /\b\d{1,2}:\d{1,2}:\d{1,2}(?:[.,:]\d+)?(?:\s?[+-]\d{2,4}|Z)?\b/,
97+
alias: 'number'
98+
},
99+
100+
'boolean': /\b(?:true|false|null)\b/i,
101+
'number': {
102+
pattern: /(^|[^.\w])(?:0x[a-f0-9]+|0o[0-7]+|0b[01]+|v?\d[\da-f]*(?:\.\d+)*(?:e[+-]?\d+)?[a-z]{0,3}\b)\b(?!\.\w)/i,
103+
lookbehind: true
104+
},
105+
106+
'operator': /[;:?<=>~/@!$%&+\-|^(){}*#]/,
107+
'punctuation': /[\[\].,]/
108+
};

components/prism-log.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-log.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<h2>Nginx example</h2>
2+
<pre><code>/47.29.201.179 - - [28/Feb/2019:13:17:10 +0000] "GET /?p=1 HTTP/2.0" 200 5316 "https://domain1.com/?p=1" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "2.75"</code></pre>
3+
<pre><code>Mar 19 22:10:18 xxxxxx journal: xxxxxxx.mylabserver.com nginx: photos.example.com 127.0.0.1 - - [19/Mar/2018:22:10:18 +0000] "GET / HTTP/1.1" 200 1863 "-" "curl/7.29.0" "-"
4+
Mar 19 22:10:24 xxxxxxx journal: xxxxxxxx.mylabserver.com nginx: photos.example.com 127.0.0.1 - - [19/Mar/2018:22:10:24 +0000] "GET / HTTP/1.1" 200 53324 "-" "curl/7.29.0" "-"</code></pre>
5+
<pre><code>TLSv1.2 AES128-SHA 1.1.1.1 "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
6+
TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 2.2.2.2 "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"
7+
TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 3.3.3.3 "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:58.0) Gecko/20100101 Firefox/58.0"
8+
TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 4.4.4.4 "Mozilla/5.0 (Android 4.4.2; Tablet; rv:65.0) Gecko/65.0 Firefox/65.0"
9+
TLSv1 AES128-SHA 5.5.5.5 "Mozilla/5.0 (Android 4.4.2; Tablet; rv:65.0) Gecko/65.0 Firefox/65.0"
10+
TLSv1.2 ECDHE-RSA-CHACHA20-POLY1305 6.6.6.6 "Mozilla/5.0 (Linux; U; Android 5.0.2; en-US; XT1068 Build/LXB22.46-28) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/12.10.2.1164 Mobile Safari/537.36"</code></pre>

plugins/show-language/prism-show-language.js

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"elisp": "Lisp",
127127
"emacs-lisp": "Lisp",
128128
"llvm": "LLVM IR",
129+
"log": "Log file",
129130
"lolcode": "LOLCODE",
130131
"md": "Markdown",
131132
"markup-templating": "Markup templating",

plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)