Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not coloring like logs on changing extension #3

Open
ishandutta2007 opened this issue Jul 17, 2019 · 3 comments
Open

Not coloring like logs on changing extension #3

ishandutta2007 opened this issue Jul 17, 2019 · 3 comments

Comments

@ishandutta2007
Copy link

My logs are dumped at /var/mail/ishandutta2007
So in ~/.vimrc instead of
autocmd BufRead,BufNewFile *.log set syntax=log4j
I entered:
autocmd BufRead,BufNewFile /var/mail/ishandutta2007 set syntax=log4j

@tetsuo13
Copy link
Owner

autocmd is used to denote a file extension that you want to force the log4j syntax for. Specifying *.log means any file opened with the ".log" extension will be applied. In your example, you specified a root directory however. If you mean that any file under this directory should use the log4j syntax then you might want to try something like this:

autocmd BufRead,BufNewFile /var/mail/ishandutta2007/* set syntax=log4j

@ishandutta2007
Copy link
Author

still no luck :(

@ishandutta2007
Copy link
Author

ishandutta2007 commented Aug 14, 2019

@tetsuo13 Pasting my full terminal view to confirm that I haven't missed any step.

ishandutta2007@MacBook-Pro:~/Dropbox$ cat ~/.vimrc

autocmd BufRead,BufNewFile /var/mail/ishandutta2007/* set syntax=log4j

ishandutta2007@MacBook-Pro:~/Dropbox$ ls ~/.vim/syntax
log4j.vim

ishandutta2007@MacBook-Pro:~/Dropbox$ cat ~/.vim/syntax/log4j.vim

" Apache log4j and log4php syntax file.
" Language:    Apache log4j/log4php log file
" Maintainer:  Andrei Nicholson <[email protected]>
" Last Change: 2012-07-06
" Version:     0.3
"
" While it's possible to define any sort of pattern via PatternLayout (log4j)
" or LoggerLayoutPattern (log4php), this syntax file focuses on the default
" TTCC layout TTCC layout with conversion pattern set to:
"
"     %d{m/d/y H:i:s,u} [%t] %p %c %x - %m%n

if version < 600
    syntax clear
elseif exists("b:current_syntax")
    finish
endif

syn case ignore

" First element must be abbreviated month. Could be a better way.
syn match log4jHeader    "^[a-z]\{3}.\{-} - " contains=log4jDate,log4jProcessid,log4jLogger,log4jErrorlevel
syn match log4jDate      contained "^[a-z]\{3} [a-z]\{3}\s\{1,2}[0-9]\{1,2} [0-9]\{2}:[0-9]\{2}:[0-9]\{2} [0-9]\{4}\(,[0-9]\{3}\)\?"
syn match log4jProcessid contained "\[[0-9]*\]"
syn match log4jLogger    contained "[a-z\-.]* -"

syn case match

syn match log4jErrorlevel contained "\(DEBUG\|ERROR\|FATAL\|INFO\|TRACE\|WARN\)"

if version >= 508 || !exists("did_log4j_syntax_inits")
    if version < 508
        let did_log4j_syntax_inits = 1
        command! -nargs=+ HiLink hi link <args>
    else
        command! -nargs=+ HiLink hi def link <args>
    endif

    HiLink log4jDate       Type
    HiLink log4jErrorlevel Keyword
    HiLink log4jProcessid  Function
    HiLink log4jLogger     Delimiter

    delcommand HiLink
endif

let b:current_syntax = "log4j"

ishandutta2007@MacBook-Pro:~/Dropbox$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants