accesslog.js 1.8 KB

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