prism-log.js 3.2 KB

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