"Logstash and vim"

After my mature hissy fit on twitter.

Is there a grok pattern for logstash configuration files so they don’t look like perl? - @benjammingh

Eventually, once I picked my toys up from the floor (and apologised to @jordansissel), I figured I could do something about this.

So I found logstash.vim which does syntax highlighting for you. Ace, that works.

However, looking at the ftdetect for it, it relies on the filename ending in .conf and the first 10 lines ofo the file containing any of the main types of functions in logstash.

Which is a cute hack, but that doesn't help me that much, as at Etsy we use this Chef thing, and a lot of our ELK configuration is in templates. These templates don't end with .conf, they end with .erb, because they're Rubby templates.

So I made this ugly hack, for ~/.vimrc:

" Use this with https://github.com/robbles/logstash.vim
function Logstashft[]
    let logstash_rexeps = ('/Users/ben/src/chef/cookbooks/logstash/templates/default/.*logstash_.*.erb' , '/etc/logstash.*')
    let myfilename = fnameescape[expand['%:p']]

    for reggy in logstash_rexeps
        if myfilename =~# reggy
            setlocal filetype=logstash

" Same as the hack below, but for logstash files.
autocmd BufRead,BufNewFile * call Logstashft[]

You statically define some regexps, and if the file matches them, it sets the filetype to be logstash. Now I can edit the templates and vim will do it's best to make them colourful.


Comments !