├── doc └── screenshot.jpg ├── .gitignore ├── ftdetect └── log.vim ├── LICENSE ├── README.md └── syntax └── log.vim /doc/screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTDL9/vim-log-highlighting/HEAD/doc/screenshot.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Local Project resources and examples too large to commit 3 | localResources/ 4 | 5 | -------------------------------------------------------------------------------- /ftdetect/log.vim: -------------------------------------------------------------------------------- 1 | 2 | au BufNewFile,BufRead *.log set filetype=log 3 | au BufNewFile,BufRead *_log set filetype=log 4 | au BufNewFile,BufRead *.LOG set filetype=log 5 | au BufNewFile,BufRead *_LOG set filetype=log 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 MTDL9 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vim Log Highlighting 2 | 3 | ![Log highlighting example](doc/screenshot.jpg) 4 | 5 | ## Overview 6 | 7 | Provides syntax highlighting for generic log files in VIM. 8 | 9 | Some of the highlighted elements are: 10 | - Dates and times 11 | - Common log level keywords like ERROR, INFO, DEBUG 12 | - Numbers, booleans and strings 13 | - URLs and file paths 14 | - IP and MAC addresses 15 | - SysLog format columns 16 | - XML Tags 17 | 18 | 19 | 20 | ## Installation 21 | 22 | ### [VimPlug](https://github.com/junegunn/vim-plug) 23 | 24 | Add `Plug 'mtdl9/vim-log-highlighting'` to your `~/.vimrc` and run `PlugInstall`. 25 | 26 | ### [Vundle](https://github.com/gmarik/Vundle.vim) 27 | 28 | Add `Plugin 'mtdl9/vim-log-highlighting'` to your `~/.vimrc` and run `PluginInstall`. 29 | 30 | ### [Pathogen](https://github.com/tpope/vim-pathogen) 31 | 32 | $ git clone https://github.com/mtdl9/vim-log-highlighting ~/.vim/bundle/vim-log-highlighting 33 | 34 | ### Manual Install 35 | 36 | Copy the contents of the `ftdetect` and `syntax` folders in their respective ~/.vim/\* counterparts. 37 | 38 | 39 | 40 | ## Configuration 41 | 42 | Once installed, the syntax highlighting will be enabled by default for files ending with `.log` and `_log` suffixes. 43 | 44 | By default only uppercase keywords are recognized as level indicators in the log files. 45 | You can add additional log level keywords using the standard VIM syntax functions, for example by adding this to your `.vimrc` file: 46 | 47 | ```viml 48 | " Add custom level identifiers 49 | au rc Syntax log syn keyword logLevelError MY_CUSTOM_ERROR_KEYWORD 50 | ``` 51 | 52 | Likewise you can disable highlighting for elements you don't need: 53 | 54 | ```viml 55 | " Remove highlighting for URLs 56 | au rc Syntax log syn clear logUrl 57 | ``` 58 | 59 | 60 | 61 | ## Related Projects 62 | 63 | * VIM Built-in /var/log/messages highlighting 64 | * [vim-log-syntax](https://github.com/dzeban/vim-log-syntax) by dzeban 65 | * [vim-log4j](https://github.com/tetsuo13/Vim-log4j) by tetsuo13 66 | * [ccze](https://github.com/cornet/ccze) by cornet 67 | -------------------------------------------------------------------------------- /syntax/log.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: Generic log file 3 | " Maintainer: MTDL9 4 | " Latest Revision: 2020-08-23 5 | 6 | if exists('b:current_syntax') 7 | finish 8 | endif 9 | 10 | let s:cpo_save = &cpoptions 11 | set cpoptions&vim 12 | 13 | 14 | " Operators 15 | "--------------------------------------------------------------------------- 16 | syn match logOperator display '[;,\?\:\.\<=\>\~\/\@\!$\%&\+\-\|\^(){}\*#]' 17 | syn match logBrackets display '[\[\]]' 18 | syn match logEmptyLines display '-\{3,}' 19 | syn match logEmptyLines display '\*\{3,}' 20 | syn match logEmptyLines display '=\{3,}' 21 | syn match logEmptyLines display '- - ' 22 | 23 | 24 | " Constants 25 | "--------------------------------------------------------------------------- 26 | syn match logNumber '\<-\?\d\+\>' 27 | syn match logHexNumber '\<0[xX]\x\+\>' 28 | syn match logHexNumber '\<\d\x\+\>' 29 | syn match logBinaryNumber '\<0[bB][01]\+\>' 30 | syn match logFloatNumber '\<\d.\d\+[eE]\?\>' 31 | 32 | syn keyword logBoolean TRUE FALSE True False true false 33 | syn keyword logNull NULL Null null 34 | 35 | syn region logString start=/"/ end=/"/ end=/$/ skip=/\\./ 36 | " Quoted strings, but no match on quotes like "don't", "plurals' elements" 37 | syn region logString start=/'\(s \|t \| \w\)\@!/ end=/'/ end=/$/ end=/s / skip=/\\./ 38 | 39 | 40 | " Dates and Times 41 | "--------------------------------------------------------------------------- 42 | " Matches 2018-03-12T or 12/03/2018 or 12/Mar/2018 43 | syn match logDate '\d\{2,4}[-\/]\(\d\{2}\|Jan\|Feb\|Mar\|Apr\|May\|Jun\|Jul\|Aug\|Sep\|Oct\|Nov\|Dec\)[-\/]\d\{2,4}T\?' 44 | " Matches 8 digit numbers at start of line starting with 20 45 | syn match logDate '^20\d\{6}' 46 | " Matches Fri Jan 09 or Feb 11 or Apr 3 or Sun 3 47 | syn keyword logDate Mon Tue Wed Thu Fri Sat Sun Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec nextgroup=logDateDay 48 | syn match logDateDay '\s\{1,2}\d\{1,2}' contained 49 | 50 | " Matches 12:09:38 or 00:03:38.129Z or 01:32:12.102938 +0700 51 | syn match logTime '\d\{2}:\d\{2}:\d\{2}\(\.\d\{2,6}\)\?\(\s\?[-+]\d\{2,4}\|Z\)\?\>' nextgroup=logTimeZone,logSysColumns skipwhite 52 | 53 | " Follows logTime, matches UTC or PDT 2019 or 2019 EDT 54 | syn match logTimeZone '[A-Z]\{2,5}\>\( \d\{4}\)\?' contained 55 | syn match logTimeZone '\d\{4} [A-Z]\{2,5}\>' contained 56 | 57 | 58 | " Entities 59 | "--------------------------------------------------------------------------- 60 | syn match logUrl 'http[s]\?:\/\/[^\n|,; '"]\+' 61 | syn match logDomain /\v(^|\s)(\w|-)+(\.(\w|-)+)+\s/ 62 | syn match logUUID '\w\{8}-\w\{4}-\w\{4}-\w\{4}-\w\{12}' 63 | syn match logMD5 '\<[a-z0-9]\{32}\>' 64 | syn match logIPV4 '\<\d\{1,3}\(\.\d\{1,3}\)\{3}\>' 65 | syn match logIPV6 '\<\x\{1,4}\(:\x\{1,4}\)\{7}\>' 66 | syn match logMacAddress '\<\x\{2}\(:\x\{2}\)\{5}' 67 | syn match logFilePath '\<\w:\\[^\n|,; ()'"\]{}]\+' 68 | syn match logFilePath '[^a-zA-Z0-9"']\@<=\/\w[^\n|,; ()'"\]{}]\+' 69 | 70 | 71 | " Syslog Columns 72 | "--------------------------------------------------------------------------- 73 | " Syslog hostname, program and process number columns 74 | syn match logSysColumns '\w\(\w\|\.\|-\)\+ \(\w\|\.\|-\)\+\(\[\d\+\]\)\?:' contains=logOperator,logSysProcess contained 75 | syn match logSysProcess '\(\w\|\.\|-\)\+\(\[\d\+\]\)\?:' contains=logOperator,logNumber,logBrackets contained 76 | 77 | 78 | " XML Tags 79 | "--------------------------------------------------------------------------- 80 | " Simplified matches, not accurate with the spec to avoid false positives 81 | syn match logXmlHeader // contains=logString,logXmlAttribute,logXmlNamespace 82 | syn match logXmlDoctype /]*>/ contains=logString,logXmlAttribute,logXmlNamespace 83 | syn match logXmlTag /<\/\?\(\(\w\|-\)\+:\)\?\(\w\|-\)\+\(\(\n\|\s\)\+\(\(\w\|-\)\+:\)\?\(\w\|-\)\+\(="[^"]*"\|='[^']*'\)\?\)*\s*\/\?>/ contains=logString,logXmlAttribute,logXmlNamespace 84 | syn match logXmlAttribute contained "\w\+=" contains=logOperator 85 | syn match logXmlAttribute contained "\(\n\|\s\)\(\(\w\|-\)\+:\)\?\(\w\|-\)\+\(=\)\?" contains=logXmlNamespace,logOperator 86 | syn match logXmlNamespace contained "\(\w\|-\)\+:" contains=logOperator 87 | syn region logXmlComment start=// 88 | syn match logXmlCData // 89 | syn match logXmlEntity /&#\?\w\+;/ 90 | 91 | 92 | " Levels 93 | "--------------------------------------------------------------------------- 94 | syn keyword logLevelEmergency EMERGENCY EMERG 95 | syn keyword logLevelAlert ALERT 96 | syn keyword logLevelCritical CRITICAL CRIT FATAL 97 | syn keyword logLevelError ERROR ERR FAILURE SEVERE 98 | syn keyword logLevelWarning WARNING WARN 99 | syn keyword logLevelNotice NOTICE 100 | syn keyword logLevelInfo INFO 101 | syn keyword logLevelDebug DEBUG FINE 102 | syn keyword logLevelTrace TRACE FINER FINEST 103 | 104 | 105 | " Highlight links 106 | "--------------------------------------------------------------------------- 107 | hi def link logNumber Number 108 | hi def link logHexNumber Number 109 | hi def link logBinaryNumber Number 110 | hi def link logFloatNumber Float 111 | hi def link logBoolean Boolean 112 | hi def link logNull Constant 113 | hi def link logString String 114 | 115 | hi def link logDate Identifier 116 | hi def link logDateDay Identifier 117 | hi def link logTime Function 118 | hi def link logTimeZone Identifier 119 | 120 | hi def link logUrl Underlined 121 | hi def link logDomain Label 122 | hi def link logUUID Label 123 | hi def link logMD5 Label 124 | hi def link logIPV4 Label 125 | hi def link logIPV6 ErrorMsg 126 | hi def link logMacAddress Label 127 | hi def link logFilePath Conditional 128 | 129 | hi def link logSysColumns Conditional 130 | hi def link logSysProcess Include 131 | 132 | hi def link logXmlHeader Function 133 | hi def link logXmlDoctype Function 134 | hi def link logXmlTag Identifier 135 | hi def link logXmlAttribute Type 136 | hi def link logXmlNamespace Include 137 | hi def link logXmlComment Comment 138 | hi def link logXmlCData String 139 | hi def link logXmlEntity Special 140 | 141 | hi def link logOperator Operator 142 | hi def link logBrackets Comment 143 | hi def link logEmptyLines Comment 144 | 145 | hi def link logLevelEmergency ErrorMsg 146 | hi def link logLevelAlert ErrorMsg 147 | hi def link logLevelCritical ErrorMsg 148 | hi def link logLevelError ErrorMsg 149 | hi def link logLevelWarning WarningMsg 150 | hi def link logLevelNotice Character 151 | hi def link logLevelInfo Repeat 152 | hi def link logLevelDebug Debug 153 | hi def link logLevelTrace Comment 154 | 155 | 156 | 157 | let b:current_syntax = 'log' 158 | 159 | let &cpoptions = s:cpo_save 160 | unlet s:cpo_save 161 | 162 | --------------------------------------------------------------------------------