1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-13 18:25:42 +08:00

feat(logger): add syntax highlighting for runtime log

This commit is contained in:
Shidong Wang 2021-10-29 20:52:14 +08:00
parent b07f22875e
commit be7d6130d6
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848
6 changed files with 20 additions and 10 deletions

View File

@ -49,7 +49,7 @@ endfunction
function! s:self.error(msg) abort
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
echohl Error
echom log

View File

@ -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 . ' '
elseif &filetype ==# 'TransientState'
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'
return '%#SpaceVim_statusline_a#' . s:winnr() . ' VimCalc %#SpaceVim_statusline_a_SpaceVim_statusline_b#'
elseif &filetype ==# 'HelpDescribe'

View File

@ -87,11 +87,7 @@ else
function! SpaceVim#logger#viewRuntimeLog() abort
let info = "### SpaceVim runtime log :\n\n"
let info .= "```log\n"
let info .= s:LOGGER.view(s:LOGGER.level)
let info .= "\n```\n"
tabnew +setl\ nobuflisted
nnoremap <buffer><silent> q :tabclose!<CR>
for msg in split(info, "\n")
@ -100,6 +96,7 @@ else
normal! "_dd
setl nomodifiable
setl buftype=nofile
setl filetype=SpaceVimLog
endfunction

View File

@ -21,7 +21,7 @@ local M = {
-- 1 : log info, warn, error messages
-- 2 : log warn, error messages
-- 3 : log error messages
M.levels = {'Info', 'Warn', 'Error', 'Debug'}
M.levels = {'Info ', 'Warn ', 'Error', 'Debug'}
function M.set_silent(sl)
M.silent = sl
@ -38,7 +38,7 @@ end
function M._build_msg(msg, l)
msg = msg or ''
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
end

View File

@ -44,9 +44,7 @@ end
function M.viewRuntimeLog()
local info = "### SpaceVim runtime log :\n\n"
.. "```log\n"
.. logger.view(logger.level)
.. "\n```\n"
cmd('tabnew')
cmd('setl nobuflisted')
cmd('nnoremap <buffer><silent> q :tabclose!<CR>')
@ -54,7 +52,7 @@ function M.viewRuntimeLog()
fn.append(0, fn.split(info, "\n"))
cmd('setl nomodifiable')
cmd('setl buftype=nofile')
-- cmd('setl filetype=markdown')
cmd('setl filetype=SpaceVimLog')
-- M.syntax_extra()
end

13
syntax/SpaceVimLog.vim Normal file
View 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