mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-14 10:45:42 +08:00
feat(logger): add syntax highlighting for runtime log
This commit is contained in:
parent
b07f22875e
commit
be7d6130d6
@ -49,7 +49,7 @@ endfunction
|
|||||||
|
|
||||||
function! s:self.error(msg) abort
|
function! s:self.error(msg) abort
|
||||||
let time = strftime('%H:%M:%S')
|
let time = strftime('%H:%M:%S')
|
||||||
let log = '[ ' . self.name . ' ] [' . time . '] [ ' . s:levels[2] . ' ] ' . a:msg
|
let log = '[ ' . self.name . ' ] [' . time . '] [ ' . s:levels[2] . '] ' . a:msg
|
||||||
if !self.silent && self.verbose >= 1
|
if !self.silent && self.verbose >= 1
|
||||||
echohl Error
|
echohl Error
|
||||||
echom log
|
echom log
|
||||||
|
@ -543,6 +543,8 @@ function! SpaceVim#layers#core#statusline#get(...) abort
|
|||||||
\ . '%#SpaceVim_statusline_b# %{SpaceVim#plugins#flygrep#lineNr()} %#SpaceVim_statusline_b_SpaceVim_statusline_z#' . s:lsep . ' '
|
\ . '%#SpaceVim_statusline_b# %{SpaceVim#plugins#flygrep#lineNr()} %#SpaceVim_statusline_b_SpaceVim_statusline_z#' . s:lsep . ' '
|
||||||
elseif &filetype ==# 'TransientState'
|
elseif &filetype ==# 'TransientState'
|
||||||
return '%#SpaceVim_statusline_a# Transient State %#SpaceVim_statusline_a_SpaceVim_statusline_b#'
|
return '%#SpaceVim_statusline_a# Transient State %#SpaceVim_statusline_a_SpaceVim_statusline_b#'
|
||||||
|
elseif &filetype ==# 'SpaceVimLog'
|
||||||
|
return '%#SpaceVim_statusline_a# SpaceVim Runtime log %#SpaceVim_statusline_a_SpaceVim_statusline_b#'
|
||||||
elseif &filetype ==# 'vimcalc'
|
elseif &filetype ==# 'vimcalc'
|
||||||
return '%#SpaceVim_statusline_a#' . s:winnr() . ' VimCalc %#SpaceVim_statusline_a_SpaceVim_statusline_b#'
|
return '%#SpaceVim_statusline_a#' . s:winnr() . ' VimCalc %#SpaceVim_statusline_a_SpaceVim_statusline_b#'
|
||||||
elseif &filetype ==# 'HelpDescribe'
|
elseif &filetype ==# 'HelpDescribe'
|
||||||
|
@ -87,11 +87,7 @@ else
|
|||||||
|
|
||||||
function! SpaceVim#logger#viewRuntimeLog() abort
|
function! SpaceVim#logger#viewRuntimeLog() abort
|
||||||
let info = "### SpaceVim runtime log :\n\n"
|
let info = "### SpaceVim runtime log :\n\n"
|
||||||
let info .= "```log\n"
|
|
||||||
|
|
||||||
let info .= s:LOGGER.view(s:LOGGER.level)
|
let info .= s:LOGGER.view(s:LOGGER.level)
|
||||||
|
|
||||||
let info .= "\n```\n"
|
|
||||||
tabnew +setl\ nobuflisted
|
tabnew +setl\ nobuflisted
|
||||||
nnoremap <buffer><silent> q :tabclose!<CR>
|
nnoremap <buffer><silent> q :tabclose!<CR>
|
||||||
for msg in split(info, "\n")
|
for msg in split(info, "\n")
|
||||||
@ -100,6 +96,7 @@ else
|
|||||||
normal! "_dd
|
normal! "_dd
|
||||||
setl nomodifiable
|
setl nomodifiable
|
||||||
setl buftype=nofile
|
setl buftype=nofile
|
||||||
|
setl filetype=SpaceVimLog
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ local M = {
|
|||||||
-- 1 : log info, warn, error messages
|
-- 1 : log info, warn, error messages
|
||||||
-- 2 : log warn, error messages
|
-- 2 : log warn, error messages
|
||||||
-- 3 : log error messages
|
-- 3 : log error messages
|
||||||
M.levels = {'Info', 'Warn', 'Error', 'Debug'}
|
M.levels = {'Info ', 'Warn ', 'Error', 'Debug'}
|
||||||
|
|
||||||
function M.set_silent(sl)
|
function M.set_silent(sl)
|
||||||
M.silent = sl
|
M.silent = sl
|
||||||
@ -38,7 +38,7 @@ end
|
|||||||
function M._build_msg(msg, l)
|
function M._build_msg(msg, l)
|
||||||
msg = msg or ''
|
msg = msg or ''
|
||||||
local time = fn.strftime('%H:%M:%S')
|
local time = fn.strftime('%H:%M:%S')
|
||||||
local log = '[ ' .. M.name .. ' ] [' .. time .. '] [ ' .. M.levels[l] .. ' ] ' .. msg
|
local log = '[ ' .. M.name .. ' ] [' .. time .. '] [ ' .. M.levels[l] .. '] ' .. msg
|
||||||
return log
|
return log
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -44,9 +44,7 @@ end
|
|||||||
|
|
||||||
function M.viewRuntimeLog()
|
function M.viewRuntimeLog()
|
||||||
local info = "### SpaceVim runtime log :\n\n"
|
local info = "### SpaceVim runtime log :\n\n"
|
||||||
.. "```log\n"
|
|
||||||
.. logger.view(logger.level)
|
.. logger.view(logger.level)
|
||||||
.. "\n```\n"
|
|
||||||
cmd('tabnew')
|
cmd('tabnew')
|
||||||
cmd('setl nobuflisted')
|
cmd('setl nobuflisted')
|
||||||
cmd('nnoremap <buffer><silent> q :tabclose!<CR>')
|
cmd('nnoremap <buffer><silent> q :tabclose!<CR>')
|
||||||
@ -54,7 +52,7 @@ function M.viewRuntimeLog()
|
|||||||
fn.append(0, fn.split(info, "\n"))
|
fn.append(0, fn.split(info, "\n"))
|
||||||
cmd('setl nomodifiable')
|
cmd('setl nomodifiable')
|
||||||
cmd('setl buftype=nofile')
|
cmd('setl buftype=nofile')
|
||||||
-- cmd('setl filetype=markdown')
|
cmd('setl filetype=SpaceVimLog')
|
||||||
-- M.syntax_extra()
|
-- M.syntax_extra()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
13
syntax/SpaceVimLog.vim
Normal file
13
syntax/SpaceVimLog.vim
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
if exists('b:current_syntax') && b:current_syntax ==# 'SpaceVimLog'
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let b:current_syntax = 'SpaceVimLog'
|
||||||
|
syntax case ignore
|
||||||
|
|
||||||
|
syn match SPCLogHead /^###.*/
|
||||||
|
syn match SPCLogWarn /^.*\[ Warn ].*/
|
||||||
|
syn match SPCLogError /^.*\[ Error].*/
|
||||||
|
hi def link SPCLogHead TODO
|
||||||
|
hi def link SPCLogWarn WarningMsg
|
||||||
|
hi def link SPCLogError Error
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user