UNPKG

3.29 kBJavaScriptView Raw
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
6Prism.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 'exception': {
14 pattern: /(^|[^\w.])[a-z][\w.]*(?:Error|Exception):.*(?:(?:\r\n?|\n)[ \t]*(?:at[ \t].+|\.{3}.*|Caused by:.*))+(?:(?:\r\n?|\n)[ \t]*\.\.\. .*)?/,
15 lookbehind: true,
16 greedy: true,
17 alias: ['javastacktrace', 'language-javastacktrace'],
18 inside: Prism.languages['javastacktrace'] || {
19 'keyword': /\bat\b/,
20 'function': /[a-z_][\w$]*(?=\()/,
21 'punctuation': /[.:()]/
22 }
23 },
24
25 'level': [
26 {
27 pattern: /\b(?:ALERT|CRIT|CRITICAL|EMERG|EMERGENCY|ERR|ERROR|FAILURE|FATAL|SEVERE)\b/,
28 alias: ['error', 'important']
29 },
30 {
31 pattern: /\b(?:WARN|WARNING|WRN)\b/,
32 alias: ['warning', 'important']
33 },
34 {
35 pattern: /\b(?:DISPLAY|INF|INFO|NOTICE|STATUS)\b/,
36 alias: ['info', 'keyword']
37 },
38 {
39 pattern: /\b(?:DBG|DEBUG|FINE)\b/,
40 alias: ['debug', 'keyword']
41 },
42 {
43 pattern: /\b(?:FINER|FINEST|TRACE|TRC|VERBOSE|VRB)\b/,
44 alias: ['trace', 'comment']
45 }
46 ],
47
48 'property': {
49 pattern: /((?:^|[\]|])[ \t]*)[a-z_](?:[\w-]|\b\/\b)*(?:[. ]\(?\w(?:[\w-]|\b\/\b)*\)?)*:(?=\s)/im,
50 lookbehind: true
51 },
52
53 'separator': {
54 pattern: /(^|[^-+])-{3,}|={3,}|\*{3,}|- - /m,
55 lookbehind: true,
56 alias: 'comment'
57 },
58
59 'url': /\b(?:file|ftp|https?):\/\/[^\s|,;'"]*[^\s|,;'">.]/,
60 'email': {
61 pattern: /(^|\s)[-\w+.]+@[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+(?=\s)/,
62 lookbehind: true,
63 alias: 'url'
64 },
65
66 'ip-address': {
67 pattern: /\b(?:\d{1,3}(?:\.\d{1,3}){3})\b/,
68 alias: 'constant'
69 },
70 'mac-address': {
71 pattern: /\b[a-f0-9]{2}(?::[a-f0-9]{2}){5}\b/i,
72 alias: 'constant'
73 },
74 'domain': {
75 pattern: /(^|\s)[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)*\.[a-z][a-z0-9-]+(?=\s)/,
76 lookbehind: true,
77 alias: 'constant'
78 },
79
80 'uuid': {
81 pattern: /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/i,
82 alias: 'constant'
83 },
84 'hash': {
85 pattern: /\b(?:[a-f0-9]{32}){1,2}\b/i,
86 alias: 'constant'
87 },
88
89 'file-path': {
90 pattern: /\b[a-z]:[\\/][^\s|,;:(){}\[\]"']+|(^|[\s:\[\](>|])\.{0,2}\/\w[^\s|,;:(){}\[\]"']*/i,
91 lookbehind: true,
92 greedy: true,
93 alias: 'string'
94 },
95
96 'date': {
97 pattern: RegExp(
98 /\b\d{4}[-/]\d{2}[-/]\d{2}(?:T(?=\d{1,2}:)|(?=\s\d{1,2}:))/.source +
99 '|' +
100 /\b\d{1,4}[-/ ](?:\d{1,2}|Apr|Aug|Dec|Feb|Jan|Jul|Jun|Mar|May|Nov|Oct|Sep)[-/ ]\d{2,4}T?\b/.source +
101 '|' +
102 /\b(?:(?:Fri|Mon|Sat|Sun|Thu|Tue|Wed)(?:\s{1,2}(?:Apr|Aug|Dec|Feb|Jan|Jul|Jun|Mar|May|Nov|Oct|Sep))?|Apr|Aug|Dec|Feb|Jan|Jul|Jun|Mar|May|Nov|Oct|Sep)\s{1,2}\d{1,2}\b/.source,
103 'i'
104 ),
105 alias: 'number'
106 },
107 'time': {
108 pattern: /\b\d{1,2}:\d{1,2}:\d{1,2}(?:[.,:]\d+)?(?:\s?[+-]\d{2}:?\d{2}|Z)?\b/,
109 alias: 'number'
110 },
111
112 'boolean': /\b(?:false|null|true)\b/i,
113 'number': {
114 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,
115 lookbehind: true
116 },
117
118 'operator': /[;:?<=>~/@!$%&+\-|^(){}*#]/,
119 'punctuation': /[\[\].,]/
120};