log.vim (10121B)
1 " Vim syntax file 2 " Language: Generic log file 3 " Maintainer: Mao-Yining <https://github.com/mao-yining> 4 " Former Maintainer: MTDL9 <https://github.com/MTDL9> 5 " Latest Revision: 2025-10-31 6 7 if exists('b:current_syntax') 8 finish 9 endif 10 11 syntax case ignore 12 13 " Operators 14 "--------------------------------------------------------------------------- 15 syn match logOperator display '[;,\?\:\.\<=\>\~\/\@\!$\%&\+\-\|\^(){}\*#]' 16 syn match logBrackets display '[][]' 17 18 " For Visual Separator and Apache CLF 19 "--------------------------------------------------------------------------- 20 syn match logSeparator display '-\{3,}\|=\{3,}\|#\{3,}\|\*\{3,}\|<\{3,}\|>\{3,}' 21 syn match logSeparator display '- - ' 22 23 " Strings 24 " ------------------------------ 25 syn region LogString start=/"/ end=/"/ end=/$/ skip=/\\./ contains=logJavaError 26 syn region LogString start=/`/ end=/`/ end=/$/ skip=/\\./ contains=logJavaError 27 " Quoted strings, but no match on quotes like `don't`, possessive `s'` and `'s` 28 syn region LogString start=/\(s\)\@<!'\(s \|t \)\@!/ end=/'/ end=/$/ skip=/\\./ contains=logJavaError 29 30 " Numbers 31 "--------------------------------------------------------------------------- 32 syn match logNumber display '\<\d\+\>' 33 syn match logNumberFloat display '\<\d\+\.\d\+\([eE][-+]\=\d\+\)\=\>' 34 syn match logNumberFloat display '\<\d\+[eE][-+]\=\d\+\>' 35 syn match logNumberBin display '\<0[bB][01]\+\>' 36 syn match logNumberOct display '\<0[oO]\o\+\>' 37 syn match logNumberHex display '\<0[xX]\x\+\>' 38 39 " Possible hex numbers without the '0x' prefix 40 syn match logNumberHex display '\<\x\{4,}\>' 41 42 " Numbers in Hardware Description Languages e.g. Verilog 43 " These must be placed after LogString to ensure they take precedence 44 syn match logNumber display '\'d\d\+\>' 45 syn match logNumberBin display '\'b[01]\+\>' 46 syn match logNumberOct display '\'o\o\+\>' 47 syn match logNumberHex display '\'h\x\+\>' 48 49 " Constants 50 "--------------------------------------------------------------------------- 51 syn keyword logBoolean true false 52 syn keyword logNull null nil none 53 54 " Dates and Times 55 "--------------------------------------------------------------------------- 56 " MM-DD, DD-MM, MM/DD, DD/MM 57 syn match logDate display '\<\d\{2}[-\/]\d\{2}\>' 58 " YYYY-MM-DD, YYYY/MM/DD 59 syn match logDate display '\<\d\{4}[-\/]\d\{2}[-\/]\d\{2}\>' 60 " DD-MM-YYYY, DD/MM/YYYY 61 syn match logDate display '\<\d\{2}[-\/]\d\{2}[-\/]\d\{4}\>' 62 " First half of RFC3339 e.g. 2023-01-01T 63 syn match logDate display '\<\d\{4}-\d\{2}-\d\{2}T' 64 " 'Dec 31', 'Dec 31, 2023', 'Dec 31 2023' 65 syn match logDate display '\<\a\{3} \d\{1,2}\(,\? \d\{4}\)\?\>' 66 " '31-Dec-2023', '31 Dec 2023' 67 syn match logDate display '\<\d\{1,2}[- ]\a\{3}[- ]\d\{4}\>' 68 " Weekday string 69 syn keyword logDate Mon Tue Wed Thu Fri Sat Sun 70 " Matches 12:09:38 or 00:03:38.129Z or 01:32:12.102938 +0700 or 01:32:12.1234567890 or 21:14:18+11:00 71 syn match logTime display '\d\{2}:\d\{2}:\d\{2}\(\.\d\{2,9}\)\?\(\s\?[-+]\(\d\{1,2\}:\d\{2\}\|\d\{2,4}\)\|Z\)\?\>' nextgroup=logTimeZone,logSysColumns skipwhite 72 " Time zone e.g. Z, +08:00, PST 73 syn match logTimeZone display 'Z\|[+-]\d\{2}:\d\{2}\|\a\{3}\>' contained skipwhite nextgroup=logSysColumns 74 " Matches time durations like 1ms or 1y 2d 23ns 3.14s 1.2e4s 3E+20h 75 syn match logDuration display '\(\(\(\d\+d\)\?\d\+h\)\?\d\+m\)\?\d\+\(\.\d\+\)\?[mun]\?s\>' 76 77 " Objects 78 "--------------------------------------------------------------------------- 79 syn match logUrl display '\<https\?:\/\/\S\+' 80 syn match logMacAddress display '\<\x\{2}\([:-]\?\x\{2}\)\{5}\>' 81 syn match logIPv4 display '\<\d\{1,3}\(\.\d\{1,3}\)\{3}\(\/\d\+\)\?\>' 82 syn match logIPv6 display '\<\x\{1,4}\(:\x\{1,4}\)\{7}\(\/\d\+\)\?\>' 83 syn match logUUID display '\<\x\{8}-\x\{4}-\x\{4}-\x\{4}-\x\{12}\>' 84 syn match logMD5 display '\<\x\{32}\>' 85 syn match logSHA display '\<\(\x\{40}\|\x\{56}\|\x\{64}\|\x\{96}\|\x\{128}\)\>' 86 87 " Only highlight a path which is at the start of a line, or preceded by a space 88 " or an equal sign (for env vars, e.g. PATH=/usr/bin) 89 " POSIX-style path e.g. '/var/log/system.log', './run.sh', '../a/b', '~/c'. 90 syn match logFilePath display '\(^\|\s\|=\)\zs\(\.\{0,2}\|\~\)\/\f\+\ze' 91 " Windows drive path e.g. 'C:\Users\Test' 92 syn match logFilePath display '\(^\|\s\|=\)\zs\a:\\\f\+\ze' 93 " Windows UNC path e.g. '\\server\share' 94 syn match logFilePath display '\(^\|\s\|=\)\zs\\\\\f\+\ze' 95 96 " Java Errors 97 "--------------------------------------------------------------------------- 98 syn match logJavaError '\%(\%(Error\|Exception\):\s*\)\zs\w.\{-}\ze\(\\n\|$\)' contained 99 100 " Syslog Columns 101 "--------------------------------------------------------------------------- 102 " Syslog hostname, program and process number columns 103 syn match logSysColumns '\w\(\w\|\.\|-\)\+ \(\w\|\.\|-\)\+\(\[\d\+\]\)\?:' contains=logOperator,@logLvs,LogSysProcess contained 104 syn match logSysProcess '\(\w\|\.\|-\)\+\(\[\d\+\]\)\?:' contains=logOperator,logNumber,logBrackets contained 105 106 " XML Tags 107 "--------------------------------------------------------------------------- 108 " Simplified matches, not accurate with the spec to avoid false positives 109 syn match logXmlHeader /<?\(\w\|-\)\+\(\s\+\w\+\(="[^"]*"\|='[^']*'\)\?\)*?>/ contains=logString,logXmlAttribute,logXmlNamespace 110 syn match logXmlDoctype /<!DOCTYPE[^>]*>/ contains=logString,logXmlAttribute,logXmlNamespace 111 syn match logXmlTag /<\/\?\(\(\w\|-\)\+:\)\?\(\w\|-\)\+\(\(\n\|\s\)\+\(\(\w\|-\)\+:\)\?\(\w\|-\)\+\(="[^"]*"\|='[^']*'\)\?\)*\s*\/\?>/ contains=logString,logXmlAttribute,logXmlNamespace 112 syn match logXmlAttribute contained "\w\+=" contains=logOperator 113 syn match logXmlAttribute contained "\(\n\|\s\)\(\(\w\|-\)\+:\)\?\(\w\|-\)\+\(=\)\?" contains=logXmlNamespace,logOperator 114 syn match logXmlNamespace contained "\(\w\|-\)\+:" contains=logOperator 115 syn region logXmlComment start=/<!--/ end=/-->/ 116 syn match logXmlCData /<!\[CDATA\[.*\]\]>/ 117 syn match logXmlEntity /&#\?\w\+;/ 118 119 " Levels 120 "--------------------------------------------------------------------------- 121 syn keyword logLvFatal FATAL Fatal fatal 122 syn keyword logLvEmergency EMERG[ENCY] Emerg[ency] emerg[ency] 123 syn keyword logLvAlert ALERT Alert alert 124 syn keyword logLvCritical CRIT[ICAL] Crit[ical] crit[ical] 125 syn keyword logLvError E ERR[ORS] Err[ors] err[ors] 126 syn keyword logLvFail F FAIL[ED] Fail[ed] fail[ed] FAILURE Failure failure 127 syn keyword logLvFault FAULT Fault fault 128 syn keyword logLvNack NACK Nack nack NAK Nak nak 129 syn keyword logLvWarning W WARN[ING] Warn[ing] warn[ing] 130 syn keyword logLvBad BAD Bad bad 131 syn keyword logLvNotice NOTICE Notice notice 132 syn keyword logLvInfo I INFO Info info 133 syn keyword logLvDebug D DEBUG Debug debug DBG Dbg dbg 134 syn keyword logLvTrace TRACE Trace trace 135 syn keyword logLvVerbose V VERBOSE Verbose verbose 136 syn keyword logLvPass PASS[ED] Pass[ed] pass[ed] 137 syn keyword logLvSuccess SUCCEED[ED] Succeed[ed] succeed[ed] SUCCESS Success success 138 139 " Composite log levels e.g. *_INFO 140 syn match logLvFatal display '\<\u\+_FATAL\>' 141 syn match logLvEmergency display '\<\u\+_EMERG\(ENCY\)\?\>' 142 syn match logLvAlert display '\<\u\+_ALERT\>' 143 syn match logLvCritical display '\<\u\+_CRIT\(ICAL\)\?\>' 144 syn match logLvError display '\<\u\+_ERR\(OR\)\?\>' 145 syn match logLvFail display '\<\u\+_FAIL\(URE\)\?\>' 146 syn match logLvWarning display '\<\u\+_WARN\(ING\)\?\>' 147 syn match logLvNotice display '\<\u\+_NOTICE\>' 148 syn match logLvInfo display '\<\u\+_INFO\>' 149 syn match logLvDebug display '\<\u\+_DEBUG\>' 150 syn match logLvTrace display '\<\u\+_TRACE\>' 151 152 syn cluster logLvs contains=LogLvFatal,LogLvEmergency,LogLvAlert,LogLvCritical,LogLvError,LogLvFail,LogLvFault,LogLvNack,LogLvWarning,LogLvBad,LogLvNotice,LogLvInfo,LogLvDebug,LogLvTrace,LogLvVerbose,LogLvPass,LogLvSuccess 153 154 " Highlight links 155 "--------------------------------------------------------------------------- 156 hi def link logNumber Number 157 hi def link logNumberHex Number 158 hi def link logNumberBin Number 159 hi def link logNumberOct Number 160 hi def link logNumberFloat Float 161 162 hi def link logBoolean Boolean 163 hi def link logNull Constant 164 hi def link logString String 165 166 hi def link logDate Type 167 hi def link logTime Operator 168 hi def link logTimeZone Operator 169 hi def link logDuration Operator 170 171 hi def link logUrl Underlined 172 hi def link logIPV4 Underlined 173 hi def link logIPV6 Underlined 174 hi def link logMacAddress Underlined 175 hi def link logUUID Label 176 hi def link logMD5 Label 177 hi def link logSHA Label 178 hi def link logFilePath Structure 179 180 hi def link logJavaError ErrorMsg 181 182 hi def link logSysColumns Statement 183 hi def link logSysProcess Function 184 185 hi def link logXmlHeader Function 186 hi def link logXmlDoctype Function 187 hi def link logXmlTag Identifier 188 hi def link logXmlAttribute Type 189 hi def link logXmlNamespace Include 190 hi def link logXmlComment Comment 191 hi def link logXmlCData String 192 hi def link logXmlEntity Special 193 194 hi def link logOperator Special 195 hi def link logBrackets Special 196 hi def link logSeparator Comment 197 198 hi def link LogLvFatal ErrorMsg 199 hi def link LogLvEmergency ErrorMsg 200 hi def link LogLvAlert ErrorMsg 201 hi def link LogLvCritical ErrorMsg 202 hi def link LogLvError ErrorMsg 203 hi def link LogLvFail ErrorMsg 204 hi def link LogLvFault ErrorMsg 205 hi def link LogLvNack ErrorMsg 206 hi def link LogLvWarning WarningMsg 207 hi def link LogLvBad WarningMsg 208 hi def link LogLvNotice Exception 209 hi def link LogLvInfo LogBlue 210 hi def link LogLvDebug Debug 211 hi def link LogLvTrace Special 212 hi def link LogLvVerbose Special 213 hi def link LogLvPass LogGreen 214 hi def link LogLvSuccess LogGreen 215 216 " Custom highlight group 217 " ------------------------------ 218 hi logGreen ctermfg=lightgreen guifg=#a4c672 219 hi logBlue ctermfg=lightblue guifg=#92bcfc 220 221 222 let b:current_syntax = 'log'