A simple and lightweight Neovim plugin that brings syntax highlighting to generic log files and provides straightforward configuration to manage filetype detection rules for your logs.
Use your favorite plugin manager to install the plugin.
{
'fei6409/log-highlight.nvim',
opts = {},
},
Plug 'fei6409/log-highlight.nvim'
Don't forget to add syntax on
in your .vimrc
, init.vim
, or init.lua
to
enable syntax highlighting.
This plugin uses Neovim's built-in filetype detection mechanism.
By default, the log
filetype is applied to files with a .log
extension
(e.g., sys.log
) after setup.
You can customize the filetype detection patterns as follows:
require('log-highlight').setup {
---@type string|string[]
-- File extensions
extension = 'log',
---@type string|string[]
-- File names or full file paths
filename = {
'syslog',
},
---@type string|string[]
-- File path glob patterns
-- Note: In Lua, `%` escapes special characters to match them literally.
pattern = {
'%/var%/log%/.*',
'console%-ramoops.*',
'log.*%.txt',
'logcat.*',
},
}
By default, the log
filetype is applied to files matching *.log
or *_log
.
To add custom patterns, add autocommands to your .vimrc
like this:
" Example:
autocmd BufNewFile,BufRead /var/log/* set filetype=log
Bug reports, feature requests, and pull requests are welcome. When opening an issue or PR, please consider attaching a snippet of the relevant log pattern.
If you are submitting a pull request, please also consider adding new log
samples to the samples/
directory:
patterns.log
.This helps verify that new changes do not break existing syntax highlighting.
This project is licensed under the MIT License.