mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-04-14 23:49:19 +08:00
Fix logger
This commit is contained in:
parent
8841a40435
commit
e88feb06a0
@ -1,11 +1,11 @@
|
||||
|
||||
let s:self = {
|
||||
\ 'name' : '',
|
||||
\ 'silent' : 1,
|
||||
\ 'level' : 1,
|
||||
\ 'file' : '',
|
||||
\ 'temp' : [],
|
||||
\ }
|
||||
\ 'name' : '',
|
||||
\ 'silent' : 1,
|
||||
\ 'level' : 1,
|
||||
\ 'file' : '',
|
||||
\ 'temp' : [],
|
||||
\ }
|
||||
|
||||
"1 : log all messages
|
||||
"2 : log warning and error messages
|
||||
@ -13,102 +13,102 @@ let s:self = {
|
||||
let s:levels = ['Info', 'Warn', 'Error']
|
||||
|
||||
function! SpaceVim#api#logger#get() abort
|
||||
return deepcopy(s:self)
|
||||
return deepcopy(s:self)
|
||||
endfunction
|
||||
|
||||
function! s:self.set_level(l) abort
|
||||
let self.level = a:l
|
||||
let self.level = a:l
|
||||
endfunction
|
||||
|
||||
function! s:self.error(msg) abort
|
||||
let time = strftime('%H:%M:%S')
|
||||
let log = '[ ' . self.name . ' ] [' . time . '] [ ' . s:levels[2] . ' ] ' . a:msg
|
||||
if !self.silent
|
||||
echoerr log
|
||||
endif
|
||||
call self.write(log)
|
||||
let time = strftime('%H:%M:%S')
|
||||
let log = '[ ' . self.name . ' ] [' . time . '] [ ' . s:levels[2] . ' ] ' . a:msg
|
||||
if !self.silent
|
||||
echoerr log
|
||||
endif
|
||||
call self.write(log)
|
||||
endfunction
|
||||
|
||||
function! s:self.write(msg) abort
|
||||
if empty(self.file)
|
||||
call add(self.temp, a:msg)
|
||||
return
|
||||
endif
|
||||
if !isdirectory(fnamemodify(self.file, ':p:h'))
|
||||
call mkdir(expand(fnamemodify(self.file, ':p:h')), 'p')
|
||||
endif
|
||||
let flags = filewritable(self.file) ? 'a' : ''
|
||||
call writefile([a:msg], self.file, flags)
|
||||
call add(self.temp, a:msg)
|
||||
if empty(self.file)
|
||||
return
|
||||
endif
|
||||
if !isdirectory(fnamemodify(self.file, ':p:h'))
|
||||
call mkdir(expand(fnamemodify(self.file, ':p:h')), 'p')
|
||||
endif
|
||||
let flags = filewritable(self.file) ? 'a' : ''
|
||||
call writefile([a:msg], self.file, flags)
|
||||
endfunction
|
||||
|
||||
function! s:self.warn(msg) abort
|
||||
if self.level > 2
|
||||
return
|
||||
endif
|
||||
let time = strftime('%H:%M:%S')
|
||||
let log = '[ ' . self.name . ' ] [' . time . '] [ ' . s:levels[1] . ' ] ' . a:msg
|
||||
if !self.silent
|
||||
echohl WarningMsg
|
||||
echom log
|
||||
echohl None
|
||||
endif
|
||||
call self.write(log)
|
||||
if self.level > 2
|
||||
return
|
||||
endif
|
||||
let time = strftime('%H:%M:%S')
|
||||
let log = '[ ' . self.name . ' ] [' . time . '] [ ' . s:levels[1] . ' ] ' . a:msg
|
||||
if !self.silent
|
||||
echohl WarningMsg
|
||||
echom log
|
||||
echohl None
|
||||
endif
|
||||
call self.write(log)
|
||||
endfunction
|
||||
|
||||
function! s:self.info(msg) abort
|
||||
if self.level > 1
|
||||
return
|
||||
endif
|
||||
let time = strftime('%H:%M:%S')
|
||||
let log = '[ ' . self.name . ' ] [' . time . '] [ ' . s:levels[0] . ' ] ' . a:msg
|
||||
if !self.silent
|
||||
echom log
|
||||
endif
|
||||
call self.write(log)
|
||||
if self.level > 1
|
||||
return
|
||||
endif
|
||||
let time = strftime('%H:%M:%S')
|
||||
let log = '[ ' . self.name . ' ] [' . time . '] [ ' . s:levels[0] . ' ] ' . a:msg
|
||||
if !self.silent
|
||||
echom log
|
||||
endif
|
||||
call self.write(log)
|
||||
endfunction
|
||||
|
||||
function! s:self.set_name(name) abort
|
||||
let self.name = a:name
|
||||
let self.name = a:name
|
||||
endfunction
|
||||
|
||||
function! s:self.get_name() abort
|
||||
return self.name
|
||||
return self.name
|
||||
endfunction
|
||||
|
||||
function! s:self.set_file(file) abort
|
||||
let self.file = a:file
|
||||
let self.file = a:file
|
||||
endfunction
|
||||
|
||||
function! s:self.view(l) abort
|
||||
let info = ''
|
||||
if filereadable(self.file)
|
||||
let logs = readfile(self.file, '')
|
||||
let info .= join(filter(logs, 'self._comp(v:val, a:l)'), "\n")
|
||||
else
|
||||
let info .= '[ ' . self.name . ' ] : logger file ' . self.file
|
||||
\ . ' does not exists, only log for current process will be shown!'
|
||||
let info .= "\n"
|
||||
let info .= join(filter(deepcopy(self.temp), 'self._comp(v:val, a:l)'), "\n")
|
||||
endif
|
||||
return info
|
||||
let info = ''
|
||||
if filereadable(self.file)
|
||||
let logs = readfile(self.file, '')
|
||||
let info .= join(filter(logs, 'self._comp(v:val, a:l)'), "\n")
|
||||
else
|
||||
let info .= '[ ' . self.name . ' ] : logger file ' . self.file
|
||||
\ . ' does not exists, only log for current process will be shown!'
|
||||
let info .= "\n"
|
||||
let info .= join(filter(deepcopy(self.temp), 'self._comp(v:val, a:l)'), "\n")
|
||||
endif
|
||||
return info
|
||||
endfunction
|
||||
|
||||
function! s:self._comp(msg, l) abort
|
||||
if a:msg =~# '\[ ' . self.name . ' \] \[\d\d\:\d\d\:\d\d\] \[ '
|
||||
\ . s:levels[2] . ' \]'
|
||||
return 1
|
||||
elseif a:msg =~# '\[ ' . self.name . ' \] \[\d\d\:\d\d\:\d\d\] \[ '
|
||||
\ . s:levels[1] . ' \]'
|
||||
if a:l > 2
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
endif
|
||||
if a:msg =~# '\[ ' . self.name . ' \] \[\d\d\:\d\d\:\d\d\] \[ '
|
||||
\ . s:levels[2] . ' \]'
|
||||
return 1
|
||||
elseif a:msg =~# '\[ ' . self.name . ' \] \[\d\d\:\d\d\:\d\d\] \[ '
|
||||
\ . s:levels[1] . ' \]'
|
||||
if a:l > 2
|
||||
return 0
|
||||
else
|
||||
if a:l > 1
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
endif
|
||||
return 1
|
||||
endif
|
||||
else
|
||||
if a:l > 1
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
@ -1,7 +1,6 @@
|
||||
let s:LOGGER = SpaceVim#api#import('logger')
|
||||
|
||||
call s:LOGGER.set_name('SpaceVim')
|
||||
call s:LOGGER.set_file(expand('~/.cache/SpaceVim/SpaceVim.log'))
|
||||
call s:LOGGER.set_level(1)
|
||||
|
||||
function! SpaceVim#logger#info(msg)
|
||||
@ -75,7 +74,7 @@ endfunction
|
||||
|
||||
""
|
||||
" @public
|
||||
" Set the log output file of SpaceVim. Default is `~/.SpaceVim/.SpaceVim.log`.
|
||||
" Set the log output file of SpaceVim. Default is empty.
|
||||
function! SpaceVim#logger#setOutput(file) abort
|
||||
call s:LOGGER.set_file(a:file)
|
||||
endfunction
|
||||
|
@ -467,7 +467,7 @@ SpaceVim#logger#setLevel({level}) *SpaceVim#logger#setLevel()*
|
||||
3 : log error messages only
|
||||
|
||||
SpaceVim#logger#setOutput({file}) *SpaceVim#logger#setOutput()*
|
||||
Set the log output file of SpaceVim. Default is `~/.SpaceVim/.SpaceVim.log`.
|
||||
Set the log output file of SpaceVim. Default is empty.
|
||||
|
||||
==============================================================================
|
||||
LAYERS *SpaceVim-layers*
|
||||
|
@ -23,6 +23,7 @@ description: "General documentation about how to using SpaceVim, including the q
|
||||
- [Updating from the SpaceVim Buffer](#updating-from-the-spacevim-buffer)
|
||||
- [Updating Manually with git](#updating-manually-with-git)
|
||||
- [Update plugins](#update-plugins)
|
||||
- [Get SpaceVim log](#get-spacevim-log)
|
||||
- [Configuration layers](#configuration-layers)
|
||||
- [Custom Configuration](#custom-configuration)
|
||||
- [Automatic Generation](#automatic-generation)
|
||||
@ -229,6 +230,10 @@ To update manually close Vim and update the git repository:
|
||||
|
||||
Use `:SPUpdate` command will update all the plugins and SpaceVim itself. after `:SPUpdate`, you can assign plugins need to be updated. Use <kbd>Tab</kbd> to complete plugin names after `:SPUpdate`.
|
||||
|
||||
### Get SpaceVim log
|
||||
|
||||
Use `:SPDebugInfo!` command will desplay the log of SpaceVim. You also can use `SPC h I` to open a buffer with issue template.
|
||||
|
||||
## Configuration layers
|
||||
|
||||
This section is an overview of layers. A more extensive introduction to writing configuration layers can be found in [SpaceVim's layers page](http://spacevim.org/layers/) (recommended reading!).
|
||||
|
Loading…
x
Reference in New Issue
Block a user