Compare commits

...

10 Commits

Author SHA1 Message Date
MTDL9
1037e26f31 Optimize Syslog date rule using keywords in place of combinations
The previous rule used combinations of Day and Month three letter terms,
and was taking up about 30% of the syntax processing time.
The new methods using keywords has the side effect of highlighting the
three letter identifies in the whole file (they should be reasonably
rare outside of dates, however) but is much faster
2020-08-30 09:10:11 +02:00
MTDL9
5ce7cb9908 Add ftdetect matches for uppercase extensions 2020-08-29 11:59:03 +02:00
MTDL9
f8b9fc8cb7 Remove logOperator duplicate & rule and unnecessary escape slash 2020-08-23 09:33:40 +02:00
MTDL9
3c298ca495 Add correct syntax rc trigger for customization examples 2020-08-23 09:04:35 +02:00
MTDL9
94773585a9 Increment latest revision in file header 2020-08-23 08:45:50 +02:00
MTDL9
e1faf5165e Fix logXmlEntity & escape and add numeric ref. support, for #8 and #10 2020-08-23 08:39:52 +02:00
MTDL9
e880f223f0 Fix wrong slash for word delimiter on logTimeZone matcher 2019-11-24 08:43:05 +01:00
MTDL9
da332bfd33 Replace TimeZone keywords like UTC and EDT with generic uppercase match
This allows supporting all the TimeZone abbreviations, which are all
included between 2 and 5 characters according to this Wikipedia article:
https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations
2019-11-24 08:40:25 +01:00
MTDL9
1332f9d363 Add CDT Time Zone identifier to the logTimeZone matcher 2019-11-24 08:32:21 +01:00
MTDL9
f9be11a822 Update logFilePath matching to avoid matching a/b patterns
This applies only when there is a slash between words which do not start
with a leading slash
2019-11-24 08:25:20 +01:00
3 changed files with 14 additions and 11 deletions

View File

@@ -46,14 +46,14 @@ You can add additional log level keywords using the standard VIM syntax function
```viml
" Add custom level identifiers
syn keyword logLevelError MY_CUSTOM_ERROR_KEYWORD
au rc Syntax log syn keyword logLevelError MY_CUSTOM_ERROR_KEYWORD
```
Likewise you can disable highlighting for elements you don't need:
```viml
" Remove highlighting for URLs
syn clear logUrl
au rc Syntax log syn clear logUrl
```

View File

@@ -1,4 +1,5 @@
au BufNewFile,BufRead *.log set filetype=log
au BufNewFile,BufRead *_log set filetype=log
au BufNewFile,BufRead *.LOG set filetype=log
au BufNewFile,BufRead *_LOG set filetype=log

View File

@@ -1,7 +1,7 @@
" Vim syntax file
" Language: Generic log file
" Maintainer: MTDL9 <https://github.com/MTDL9>
" Latest Revision: 2019-04-16
" Latest Revision: 2020-08-23
if exists('b:current_syntax')
finish
@@ -13,7 +13,7 @@ set cpoptions&vim
" Operators
"---------------------------------------------------------------------------
syn match logOperator display '[;,\?\:\.\<=\>\~\/\@\&\!$\%\&\+\-\|\^(){}\*#]'
syn match logOperator display '[;,\?\:\.\<=\>\~\/\@\!$\%&\+\-\|\^(){}\*#]'
syn match logBrackets display '[\[\]]'
syn match logEmptyLines display '-\{3,}'
syn match logEmptyLines display '\*\{3,}'
@@ -43,15 +43,16 @@ syn region logString start=/'\(s \|t \| \w\)\@!/ end=/'/ end=/$/ end=/s / s
syn match logDate '\d\{2,4}[-\/]\(\d\{2}\|Jan\|Feb\|Mar\|Apr\|May\|Jun\|Jul\|Aug\|Sep\|Oct\|Nov\|Dec\)[-\/]\d\{2,4}T\?'
" Matches 8 digit numbers at start of line starting with 20
syn match logDate '^20\d\{6}'
" Matches Fri Jan 09 or Feb 11 or Apr 3
syn match logDate '\(\(Mon\|Tue\|Wed\|Thu\|Fri\|Sat\|Sun\) \)\?\(Jan\|Feb\|Mar\|Apr\|May\|Jun\|Jul\|Aug\|Sep\|Oct\|Nov\|Dec\) [0-9 ]\d'
" Matches Fri Jan 09 or Feb 11 or Apr 3 or Sun 3
syn keyword logDate Mon Tue Wed Thu Fri Sat Sun Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec nextgroup=logDateDay
syn match logDateDay '\s\{1,2}\d\{1,2}' contained
" Matches 12:09:38 or 00:03:38.129Z or 01:32:12.102938 +0700
syn match logTime '\d\{2}:\d\{2}:\d\{2}\(\.\d\{2,6}\)\?\(\s\?[-+]\d\{2,4}\|Z\)\?\>' nextgroup=logTimeZone,logSysColumns skipwhite
" Follows logTime, matches UTC or PDT 2019 or 2019 EDT
syn match logTimeZone '\(UTC\|PDT\|EDT\|GMT\|EST\|KST\)\( \d\{4}\)\?' contained
syn match logTimeZone '\d\{4} \(UTC\|PDT\|EDT\|GMT\|EST\|KST\)' contained
syn match logTimeZone '[A-Z]\{2,5}\>\( \d\{4}\)\?' contained
syn match logTimeZone '\d\{4} [A-Z]\{2,5}\>' contained
" Entities
@@ -64,7 +65,7 @@ syn match logIPV4 '\<\d\{1,3}\(\.\d\{1,3}\)\{3}\>'
syn match logIPV6 '\<\x\{1,4}\(:\x\{1,4}\)\{7}\>'
syn match logMacAddress '\<\x\{2}\(:\x\{2}\)\{5}'
syn match logFilePath '\<\w:\\[^\n|,; ()'"\]{}]\+'
syn match logFilePath '\/\w[^\n|,; ()'"\]{}]\+'
syn match logFilePath '[^a-zA-Z0-9"']\@<=\/\w[^\n|,; ()'"\]{}]\+'
" Syslog Columns
@@ -85,7 +86,7 @@ syn match logXmlAttribute contained "\(\n\|\s\)\(\(\w\|-\)\+:\)\?\(\w\|-\)\+\
syn match logXmlNamespace contained "\(\w\|-\)\+:" contains=logOperator
syn region logXmlComment start=/<!--/ end=/-->/
syn match logXmlCData /<!\[CDATA\[.*\]\]>/
syn match logXmlEntity /\&\w\+;/
syn match logXmlEntity /&#\?\w\+;/
" Levels
@@ -112,6 +113,7 @@ hi def link logNull Constant
hi def link logString String
hi def link logDate Identifier
hi def link logDateDay Identifier
hi def link logTime Function
hi def link logTimeZone Identifier