accesslog.js 1.5 KB

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