l0bsterssg

node.js static responsive blog post generator
Log | Files | Refs | README

accesslog.js (1839B)


      1 /*
      2  Language: Apache Access Log
      3  Author: Oleg Efimov <efimovov@gmail.com>
      4  Description: Apache/Nginx Access Logs
      5  Website: https://httpd.apache.org/docs/2.4/logs.html#accesslog
      6  */
      7 
      8  /** @type LanguageFn */
      9 function accesslog(hljs) {
     10   // https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
     11   var HTTP_VERBS = [
     12     "GET", "POST", "HEAD", "PUT", "DELETE", "CONNECT", "OPTIONS", "PATCH", "TRACE"
     13   ];
     14   return {
     15     name: 'Apache Access Log',
     16     contains: [
     17       // IP
     18       {
     19         className: 'number',
     20         begin: '^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?\\b',
     21         relevance:5
     22       },
     23       // Other numbers
     24       {
     25         className: 'number',
     26         begin: '\\b\\d+\\b',
     27         relevance: 0
     28       },
     29       // Requests
     30       {
     31         className: 'string',
     32         begin: '"(' + HTTP_VERBS.join("|") + ')', end: '"',
     33         keywords: HTTP_VERBS.join(" "),
     34         illegal: '\\n',
     35         relevance: 5,
     36         contains: [{
     37           begin: 'HTTP/[12]\\.\\d',
     38           relevance:5
     39         }]
     40       },
     41       // Dates
     42       {
     43         className: 'string',
     44         // dates must have a certain length, this prevents matching
     45         // simple array accesses a[123] and [] and other common patterns
     46         // found in other languages
     47         begin: /\[\d[^\]\n]{8,}\]/,
     48         illegal: '\\n',
     49         relevance: 1
     50       },
     51       {
     52         className: 'string',
     53         begin: /\[/, end: /\]/,
     54         illegal: '\\n',
     55         relevance: 0
     56       },
     57       // User agent / relevance boost
     58       {
     59         className: 'string',
     60         begin: '"Mozilla/\\d\\.\\d \\\(', end: '"',
     61         illegal: '\\n',
     62         relevance: 3
     63       },
     64       // Strings
     65       {
     66         className: 'string',
     67         begin: '"', end: '"',
     68         illegal: '\\n',
     69         relevance: 0
     70       }
     71     ]
     72   };
     73 }
     74 
     75 module.exports = accesslog;