]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/accesslog.js
Initial commit.
[flow-web.git] / static / highlight / languages / accesslog.js
1 /*! `accesslog` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 /*
7 Language: Apache Access Log
8 Author: Oleg Efimov <efimovov@gmail.com>
9 Description: Apache/Nginx Access Logs
10 Website: https://httpd.apache.org/docs/2.4/logs.html#accesslog
11 Category: web, logs
12 Audit: 2020
13 */
14
15 /** @type LanguageFn */
16 function accesslog(hljs) {
17 const regex = hljs.regex;
18 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
19 const HTTP_VERBS = [
20 "GET",
21 "POST",
22 "HEAD",
23 "PUT",
24 "DELETE",
25 "CONNECT",
26 "OPTIONS",
27 "PATCH",
28 "TRACE"
29 ];
30 return {
31 name: 'Apache Access Log',
32 contains: [
33 // IP
34 {
35 className: 'number',
36 begin: /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d{1,5})?\b/,
37 relevance: 5
38 },
39 // Other numbers
40 {
41 className: 'number',
42 begin: /\b\d+\b/,
43 relevance: 0
44 },
45 // Requests
46 {
47 className: 'string',
48 begin: regex.concat(/"/, regex.either(...HTTP_VERBS)),
49 end: /"/,
50 keywords: HTTP_VERBS,
51 illegal: /\n/,
52 relevance: 5,
53 contains: [
54 {
55 begin: /HTTP\/[12]\.\d'/,
56 relevance: 5
57 }
58 ]
59 },
60 // Dates
61 {
62 className: 'string',
63 // dates must have a certain length, this prevents matching
64 // simple array accesses a[123] and [] and other common patterns
65 // found in other languages
66 begin: /\[\d[^\]\n]{8,}\]/,
67 illegal: /\n/,
68 relevance: 1
69 },
70 {
71 className: 'string',
72 begin: /\[/,
73 end: /\]/,
74 illegal: /\n/,
75 relevance: 0
76 },
77 // User agent / relevance boost
78 {
79 className: 'string',
80 begin: /"Mozilla\/\d\.\d \(/,
81 end: /"/,
82 illegal: /\n/,
83 relevance: 3
84 },
85 // Strings
86 {
87 className: 'string',
88 begin: /"/,
89 end: /"/,
90 illegal: /\n/,
91 relevance: 0
92 }
93 ]
94 };
95 }
96
97 return accesslog;
98
99 })();
100
101 hljs.registerLanguage('accesslog', hljsGrammar);
102 })();