1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:00:04 +08:00

Merge pull request #158 from SpaceVim/fix_logger

Fix logger
ref #157
This commit is contained in:
Wang Shidong 2017-01-24 01:05:43 +08:00 committed by GitHub
commit cfe9de5e77
3 changed files with 33 additions and 2 deletions

View File

@ -10,3 +10,10 @@
### Output of the ":message" command, and ":echo SpaceVim#logger#viewLog()"
```log
please post log here:
```

View File

@ -1,6 +1,7 @@
let s:logger_level = g:spacevim_debug_level
let s:levels = ['Info', 'Warn', 'Error']
let s:logger_file = expand('~/.SpaceVim/.SpaceVim.log')
let s:log_temp = []
""
" @public
@ -18,18 +19,24 @@ endfunction
function! SpaceVim#logger#info(msg) abort
if g:spacevim_enable_debug && s:logger_level <= 1
call s:wite(s:warpMsg(a:msg, 1))
else
call add(s:log_temp,s:warpMsg(a:msg,1))
endif
endfunction
function! SpaceVim#logger#warn(msg) abort
if g:spacevim_enable_debug && s:logger_level <= 2
call s:wite(s:warpMsg(a:msg, 2))
else
call add(s:log_temp,s:warpMsg(a:msg,2))
endif
endfunction
function! SpaceVim#logger#error(msg) abort
if g:spacevim_enable_debug && s:logger_level <= 3
call s:wite(s:warpMsg(a:msg, 3))
else
call add(s:log_temp,s:warpMsg(a:msg,3))
endif
endfunction
@ -40,12 +47,18 @@ endfunction
function! SpaceVim#logger#viewLog(...) abort
let info = "SpaceVim Options :\n\n"
let info .= join(SpaceVim#options#list(), "\n")
let info .= "\n"
let l = a:0 > 0 ? a:1 : 1
if filereadable(s:logger_file)
let logs = readfile(s:logger_file, '')
return join(filter(logs, "v:val =~# '\[ SpaceVim \] \[\d\d\:\d\d\:\d\d\] \[" . s:levels[l] . "\]'"), "\n")
return info . join(filter(logs, "v:val =~# '\[ SpaceVim \] \[\d\d\:\d\d\:\d\d\] \[" . s:levels[l] . "\]'"), "\n")
else
return '[ SpaceVim ] : logger file ' . s:logger_file . ' does not exists!'
let info .= '[ SpaceVim ] : logger file ' . s:logger_file . ' does not exists, only log for current process will be shown!'
let info .= join(filter(s:log_temp, "v:val =~# '\[ SpaceVim \] \[\d\d\:\d\d\:\d\d\] \[" . s:levels[l] . "\]'"), "\n")
return info
endif
endfunction

View File

@ -0,0 +1,11 @@
function! SpaceVim#options#list() abort
let list = []
if has('patch-7.4.2010')
for var in getcompletion('g:spacevim_','var')
call add(list, var . ' = ' . string(get(g:, var[2:] , '')))
endfor
else
call add(list, 'your vim is too old, getcompletion() need patch7-4-2010')
endif
return list
endfunction