mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-09 08:00:05 +08:00
feat(tagbar): use default logger system
This commit is contained in:
parent
75800458a2
commit
02fadf00ff
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
!0/
|
!0/
|
||||||
|
.spacevim.log
|
||||||
doc/tags
|
doc/tags
|
||||||
doc/tags-cn
|
doc/tags-cn
|
||||||
.ropeproject/
|
.ropeproject/
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
|
|
||||||
if has('nvim-0.5.0')
|
if has('nvim-0.5.0')
|
||||||
|
""
|
||||||
|
" write message to SpaceVim runtime log with `info` level.
|
||||||
function! SpaceVim#logger#info(msg) abort
|
function! SpaceVim#logger#info(msg) abort
|
||||||
lua require("spacevim.logger").info(
|
lua require("spacevim.logger").info(
|
||||||
\ require("spacevim").eval("a:msg")
|
\ require("spacevim").eval("a:msg")
|
||||||
@ -55,7 +57,26 @@ if has('nvim-0.5.0')
|
|||||||
function! SpaceVim#logger#setOutput(file) abort
|
function! SpaceVim#logger#setOutput(file) abort
|
||||||
lua require("spacevim.logger").setOutput(require("spacevim").eval("a:file"))
|
lua require("spacevim.logger").setOutput(require("spacevim").eval("a:file"))
|
||||||
endfunction
|
endfunction
|
||||||
|
""
|
||||||
|
" Derive a new logger based on SpaceVim's runtime logger. The new logger
|
||||||
|
" provides following functions:
|
||||||
|
" 1. info(msg): like |SpaceVim#logger#info|, but include the derive name.
|
||||||
|
" 2. warn(msg): like |SpaceVim#logger#warn|
|
||||||
|
" 3. error(msg): like |SpaceVim#logger#error|
|
||||||
|
" 4. debug(msg): write debug message run SpaceVim runtime log
|
||||||
|
" 5. start_debug(): enable debug mode of derived logger.
|
||||||
|
" 6. stop_debug(): stop debug mode of derived logger.
|
||||||
|
"
|
||||||
|
" Example: >
|
||||||
|
" let s:LOGGER = SpaceVim#logger#derive('myplug')
|
||||||
|
"
|
||||||
|
" call s:LOGGER.info('hello world')
|
||||||
|
" <
|
||||||
|
"
|
||||||
|
" The this info message will be write to SpaceVim's runtime log:
|
||||||
|
" >
|
||||||
|
" [ myplug ] [00:02:54:051] [ Info ] hello world
|
||||||
|
" <
|
||||||
function! SpaceVim#logger#derive(name) abort
|
function! SpaceVim#logger#derive(name) abort
|
||||||
return luaeval('require("spacevim.logger").derive(require("spacevim").eval("a:name"))')
|
return luaeval('require("spacevim.logger").derive(require("spacevim").eval("a:name"))')
|
||||||
endfunction
|
endfunction
|
||||||
@ -176,6 +197,8 @@ else
|
|||||||
|
|
||||||
let s:derive = {}
|
let s:derive = {}
|
||||||
let s:derive.origin_name = s:LOGGER.get_name()
|
let s:derive.origin_name = s:LOGGER.get_name()
|
||||||
|
" let s:derive._debug_mode = v:false
|
||||||
|
let s:derive._debug_mode = 0
|
||||||
|
|
||||||
function! s:derive.info(msg) abort
|
function! s:derive.info(msg) abort
|
||||||
call s:LOGGER.set_name(self.derive_name)
|
call s:LOGGER.set_name(self.derive_name)
|
||||||
@ -196,9 +219,19 @@ else
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:derive.debug(msg) abort
|
function! s:derive.debug(msg) abort
|
||||||
call s:LOGGER.set_name(self.derive_name)
|
if self._debug_mode
|
||||||
call s:LOGGER.debug(a:msg)
|
call s:LOGGER.set_name(self.derive_name)
|
||||||
call s:LOGGER.set_name(self.origin_name)
|
call s:LOGGER.debug(a:msg)
|
||||||
|
call s:LOGGER.set_name(self.origin_name)
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:derive.start_debug() abort
|
||||||
|
let self._debug_mode = 1
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:derive.stop_debug() abort
|
||||||
|
let self._debug_mode = 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#logger#derive(name) abort
|
function! SpaceVim#logger#derive(name) abort
|
||||||
|
6325
bundle/tagbar/autoload/tagbar.vim
vendored
6325
bundle/tagbar/autoload/tagbar.vim
vendored
File diff suppressed because it is too large
Load Diff
62
bundle/tagbar/autoload/tagbar/debug.vim
vendored
62
bundle/tagbar/autoload/tagbar/debug.vim
vendored
@ -1,62 +0,0 @@
|
|||||||
function! tagbar#debug#start_debug(...) abort
|
|
||||||
let filename = a:0 > 0 ? a:1 : ''
|
|
||||||
|
|
||||||
if empty(filename)
|
|
||||||
let s:debug_file = 'tagbardebug.log'
|
|
||||||
else
|
|
||||||
let s:debug_file = filename
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Clear log file and start it with version info
|
|
||||||
exe 'redir! > ' . s:debug_file
|
|
||||||
silent version
|
|
||||||
redir END
|
|
||||||
|
|
||||||
" Check whether the log file could be created
|
|
||||||
if !filewritable(s:debug_file)
|
|
||||||
echomsg 'Tagbar: Unable to create log file ' . s:debug_file
|
|
||||||
let s:debug_file = ''
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
|
|
||||||
let s:debug_enabled = 1
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! tagbar#debug#stop_debug() abort
|
|
||||||
let s:debug_enabled = 0
|
|
||||||
let s:debug_file = ''
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! tagbar#debug#log(msg) abort
|
|
||||||
if s:debug_enabled
|
|
||||||
execute 'redir >> ' . s:debug_file
|
|
||||||
silent echon s:gettime() . ': ' . a:msg . "\n"
|
|
||||||
redir END
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! tagbar#debug#log_ctags_output(output) abort
|
|
||||||
if s:debug_enabled
|
|
||||||
exe 'redir! > ' . s:debug_file . '.ctags_out'
|
|
||||||
silent echon a:output
|
|
||||||
redir END
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! tagbar#debug#enabled() abort
|
|
||||||
return s:debug_enabled
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
if has('reltime')
|
|
||||||
function! s:gettime() abort
|
|
||||||
let time = split(reltimestr(reltime()), '\.')
|
|
||||||
return strftime('%Y-%m-%d %H:%M:%S.', time[0]) . time[1]
|
|
||||||
endfunction
|
|
||||||
else
|
|
||||||
function! s:gettime() abort
|
|
||||||
return strftime('%Y-%m-%d %H:%M:%S')
|
|
||||||
endfunction
|
|
||||||
endif
|
|
||||||
|
|
||||||
let s:debug_enabled = 0
|
|
||||||
let s:debug_file = ''
|
|
35
bundle/tagbar/autoload/tagbar/log.vim
vendored
Normal file
35
bundle/tagbar/autoload/tagbar/log.vim
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
"=============================================================================
|
||||||
|
" log.vim --- logger for tagbar
|
||||||
|
" Copyright (c) 2016-2019 Wang Shidong & Contributors
|
||||||
|
" Author: Wang Shidong < wsdjeg@outlook.com >
|
||||||
|
" URL: https://spacevim.org
|
||||||
|
" License: GPLv3
|
||||||
|
"=============================================================================
|
||||||
|
|
||||||
|
if exists('s:debug_enabled')
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:LOGGER =SpaceVim#logger#derive('tagbar')
|
||||||
|
|
||||||
|
function! tagbar#log#start_debug(...) abort
|
||||||
|
call s:LOGGER.info('enable debug mode!')
|
||||||
|
call s:LOGGER.start_debug()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! tagbar#log#stop_debug() abort
|
||||||
|
call s:LOGGER.info('disable debug mode!')
|
||||||
|
call s:LOGGER.stop_debug()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! tagbar#log#debug(msg) abort
|
||||||
|
call s:LOGGER.debug(a:msg)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! tagbar#log#info(msg) abort
|
||||||
|
call s:LOGGER.info(a:msg)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! tagbar#log#enabled() abort
|
||||||
|
return s:LOGGER.enabled()
|
||||||
|
endfunction
|
12
bundle/tagbar/doc/tagbar.txt
vendored
12
bundle/tagbar/doc/tagbar.txt
vendored
@ -307,15 +307,13 @@ COMMANDS *tagbar-commands*
|
|||||||
makes sense to customize. See |tagbar-extend| for more information about
|
makes sense to customize. See |tagbar-extend| for more information about
|
||||||
type configurations.
|
type configurations.
|
||||||
|
|
||||||
:TagbarDebug [logfile] *:TagbarDebug*
|
:TagbarDebug *:TagbarDebug*
|
||||||
Start debug mode. This will write debug messages to file [logfile] while
|
Start debug mode. This will put debug message to SpaceVim runtime log.
|
||||||
using Tagbar. If no argument is given "tagbardebug.log" in the current
|
which can be found via `SPC h L`
|
||||||
directory is used. Note: an existing file will be overwritten!
|
|
||||||
Note also that it is usually necessary to call this command before loading
|
|
||||||
a file that creates problems in order to get all of the needed data.
|
|
||||||
|
|
||||||
:TagbarDebugEnd *:TagbarDebugEnd*
|
:TagbarDebugEnd *:TagbarDebugEnd*
|
||||||
End debug mode, debug messages will no longer be written to the logfile.
|
End debug mode, debug messages will no longer be written SpaceVim runtime
|
||||||
|
log.
|
||||||
|
|
||||||
:TagbarForceUpdate *:TagbarForceUpdate*
|
:TagbarForceUpdate *:TagbarForceUpdate*
|
||||||
Forcefully update a file even if it exceeds the |g:tagbar_file_size_limit|
|
Forcefully update a file even if it exceeds the |g:tagbar_file_size_limit|
|
||||||
|
4
bundle/tagbar/plugin/tagbar.vim
vendored
4
bundle/tagbar/plugin/tagbar.vim
vendored
@ -193,8 +193,8 @@ command! -nargs=1 -bang TagbarSetFoldlevel call tagbar#SetFoldLevel(<args>, <ba
|
|||||||
command! -nargs=0 TagbarShowTag call tagbar#highlighttag(1, 1)
|
command! -nargs=0 TagbarShowTag call tagbar#highlighttag(1, 1)
|
||||||
command! -nargs=* TagbarCurrentTag echo tagbar#currenttag('%s', 'No current tag', <f-args>)
|
command! -nargs=* TagbarCurrentTag echo tagbar#currenttag('%s', 'No current tag', <f-args>)
|
||||||
command! -nargs=1 TagbarGetTypeConfig call tagbar#gettypeconfig(<f-args>)
|
command! -nargs=1 TagbarGetTypeConfig call tagbar#gettypeconfig(<f-args>)
|
||||||
command! -nargs=? TagbarDebug call tagbar#debug#start_debug(<f-args>)
|
command! -nargs=0 TagbarDebug call tagbar#log#start_debug()
|
||||||
command! -nargs=0 TagbarDebugEnd call tagbar#debug#stop_debug()
|
command! -nargs=0 TagbarDebugEnd call tagbar#log#stop_debug()
|
||||||
command! -nargs=0 TagbarTogglePause call tagbar#toggle_pause()
|
command! -nargs=0 TagbarTogglePause call tagbar#toggle_pause()
|
||||||
command! -nargs=0 TagbarForceUpdate call tagbar#ForceUpdate()
|
command! -nargs=0 TagbarForceUpdate call tagbar#ForceUpdate()
|
||||||
command! -nargs=0 TagbarJump call tagbar#jump()
|
command! -nargs=0 TagbarJump call tagbar#jump()
|
||||||
|
@ -1645,6 +1645,31 @@ SpaceVim#layers#load({layer}) *SpaceVim#layers#load()*
|
|||||||
\ )
|
\ )
|
||||||
<
|
<
|
||||||
|
|
||||||
|
SpaceVim#logger#info({msg}) *SpaceVim#logger#info()*
|
||||||
|
write message to SpaceVim runtime log with `info` level.
|
||||||
|
|
||||||
|
SpaceVim#logger#derive({name}) *SpaceVim#logger#derive()*
|
||||||
|
Derive a new logger based on SpaceVim's runtime logger. The new logger
|
||||||
|
provides following functions:
|
||||||
|
1. info(msg): like |SpaceVim#logger#info|, but include the derive name.
|
||||||
|
2. warn(msg): like |SpaceVim#logger#warn|
|
||||||
|
3. error(msg): like |SpaceVim#logger#error|
|
||||||
|
4. debug(msg): write debug message run SpaceVim runtime log
|
||||||
|
5. start_debug(): enable debug mode of derived logger.
|
||||||
|
6. stop_debug(): stop debug mode of derived logger.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
>
|
||||||
|
let s:LOGGER = SpaceVim#logger#derive('myplug')
|
||||||
|
|
||||||
|
call s:LOGGER.info('hello world')
|
||||||
|
<
|
||||||
|
|
||||||
|
The this info message will be write to SpaceVim's runtime log:
|
||||||
|
>
|
||||||
|
[ myplug ] [00:02:54:051] [ Info ] hello world
|
||||||
|
<
|
||||||
|
|
||||||
SpaceVim#logger#setLevel({level}) *SpaceVim#logger#setLevel()*
|
SpaceVim#logger#setLevel({level}) *SpaceVim#logger#setLevel()*
|
||||||
Set debug level of SpaceVim. Default is 1.
|
Set debug level of SpaceVim. Default is 1.
|
||||||
|
|
||||||
|
@ -11,155 +11,165 @@ local fn = vim.fn or require('spacevim').fn
|
|||||||
local cmd = require('spacevim').cmd
|
local cmd = require('spacevim').cmd
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
['name'] = '',
|
['name'] = '',
|
||||||
['silent'] = 1,
|
['silent'] = 1,
|
||||||
['level'] = 1,
|
['level'] = 1,
|
||||||
['verbose'] = 1,
|
['verbose'] = 1,
|
||||||
['file'] = '',
|
['file'] = '',
|
||||||
['temp'] = {},
|
['temp'] = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
-- 0 : log debug, info, warn, error messages
|
-- 0 : log debug, info, warn, error messages
|
||||||
-- 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' }
|
||||||
M.clock = fn.reltime()
|
M.clock = fn.reltime()
|
||||||
|
|
||||||
function M.set_silent(sl)
|
function M.set_silent(sl)
|
||||||
M.silent = sl
|
M.silent = sl
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.set_verbose(vb)
|
function M.set_verbose(vb)
|
||||||
M.verbose = vb
|
M.verbose = vb
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.set_level(l)
|
function M.set_level(l)
|
||||||
|
-- the level only can be:
|
||||||
|
-- 0 : log debug, info, warn, error messages
|
||||||
|
-- 1 : log info, warn, error messages
|
||||||
|
-- 2 : log warn, error messages
|
||||||
|
-- 3 : log error messages
|
||||||
|
if l == 0 or l == 1 or l == 2 or l == 3 then
|
||||||
M.level = l
|
M.level = l
|
||||||
|
end
|
||||||
end
|
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')
|
||||||
-- error(string.format("Tried to call API function with vim.fn: use vim.api.%s instead", key))
|
-- error(string.format("Tried to call API function with vim.fn: use vim.api.%s instead", key))
|
||||||
-- local log = '[ ' .. M.name .. ' ] [' .. time .. '] [ ' .. M.levels[l] .. '] ' .. msg
|
-- local log = '[ ' .. M.name .. ' ] [' .. time .. '] [ ' .. M.levels[l] .. '] ' .. msg
|
||||||
-- change the format to
|
-- change the format to
|
||||||
-- [ name ] [00:00:00:000] [level] msg
|
-- [ name ] [00:00:00:000] [level] msg
|
||||||
local clock = fn.reltimefloat(fn.reltime(M.clock))
|
local clock = fn.reltimefloat(fn.reltime(M.clock))
|
||||||
local h = fn.float2nr(clock / 60 / 60)
|
local h = fn.float2nr(clock / 60 / 60)
|
||||||
local m = fn.float2nr(clock / 60)
|
local m = fn.float2nr(clock / 60)
|
||||||
local s = fn.float2nr(clock) % 60
|
local s = fn.float2nr(clock) % 60
|
||||||
local mic = string.format('%00.3f', clock - fn.float2nr(clock))
|
local mic = string.format('%00.3f', clock - fn.float2nr(clock))
|
||||||
local c = string.format('%02d:%02d:%02d:%s', h, m, s, string.sub(mic, 3, -1))
|
local c = string.format('%02d:%02d:%02d:%s', h, m, s, string.sub(mic, 3, -1))
|
||||||
local log = string.format('[ %s ] [%s] [ %s ] %s',
|
local log = string.format('[ %s ] [%s] [ %s ] %s', M.name, c, M.levels[l], msg)
|
||||||
M.name,
|
return log
|
||||||
c,
|
|
||||||
M.levels[l],
|
|
||||||
msg)
|
|
||||||
return log
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.debug(msg)
|
function M.debug(msg)
|
||||||
if M.level <= 0 then
|
if M.level <= 0 then
|
||||||
local log = M._build_msg(msg, 4)
|
local log = M._build_msg(msg, 4)
|
||||||
if M.silent == 0 and M.verbose >= 4 then
|
if M.silent == 0 and M.verbose >= 4 then
|
||||||
cmd('echom "' .. log .. '"')
|
cmd('echom "' .. log .. '"')
|
||||||
end
|
|
||||||
M.write(log)
|
|
||||||
end
|
end
|
||||||
|
M.write(log)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.error(msg)
|
function M.error(msg)
|
||||||
local log = M._build_msg(msg, 3)
|
local log = M._build_msg(msg, 3)
|
||||||
if M.silent == 0 and M.verbose >= 1 then
|
if M.silent == 0 and M.verbose >= 1 then
|
||||||
cmd('echohl Error')
|
cmd('echohl Error')
|
||||||
cmd('echom "' .. log .. '"')
|
cmd('echom "' .. log .. '"')
|
||||||
cmd('echohl None')
|
cmd('echohl None')
|
||||||
end
|
end
|
||||||
M.write(log)
|
M.write(log)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.write(msg)
|
function M.write(msg)
|
||||||
table.insert(M.temp, msg)
|
table.insert(M.temp, msg)
|
||||||
if M.file ~= '' then
|
if M.file ~= '' then
|
||||||
if fn.isdirectory(fn.fnamemodify(M.file, ':p:h')) == 0 then
|
if fn.isdirectory(fn.fnamemodify(M.file, ':p:h')) == 0 then
|
||||||
fn.mkdir(fn.expand(fn.fnamemodify(M.file, ':p:h')), 'p')
|
fn.mkdir(fn.expand(fn.fnamemodify(M.file, ':p:h')), 'p')
|
||||||
end
|
|
||||||
local flags = ''
|
|
||||||
if fn.filereadable(M.file) == 1 then
|
|
||||||
flags = 'a'
|
|
||||||
end
|
|
||||||
fn.writefile({msg}, M.file, flags)
|
|
||||||
end
|
end
|
||||||
|
local flags = ''
|
||||||
|
if fn.filereadable(M.file) == 1 then
|
||||||
|
flags = 'a'
|
||||||
|
end
|
||||||
|
fn.writefile({ msg }, M.file, flags)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.warn(msg, ...)
|
function M.warn(msg, ...)
|
||||||
if M.level <= 2 then
|
if M.level <= 2 then
|
||||||
local log = M._build_msg(msg, 2)
|
local log = M._build_msg(msg, 2)
|
||||||
if (M.silent == 0 and M.verbose >= 2) or select(1, ...) == 1 then
|
if (M.silent == 0 and M.verbose >= 2) or select(1, ...) == 1 then
|
||||||
cmd('echohl WarningMsg')
|
cmd('echohl WarningMsg')
|
||||||
cmd('echom "' .. log .. '"')
|
cmd('echom "' .. log .. '"')
|
||||||
cmd('echohl None')
|
cmd('echohl None')
|
||||||
end
|
|
||||||
M.write(log)
|
|
||||||
end
|
end
|
||||||
|
M.write(log)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.info(msg)
|
function M.info(msg)
|
||||||
if M.level <= 1 then
|
if M.level <= 1 then
|
||||||
local log = M._build_msg(msg, 1)
|
local log = M._build_msg(msg, 1)
|
||||||
if M.silent == 0 and M.verbose >= 3 then
|
if M.silent == 0 and M.verbose >= 3 then
|
||||||
cmd('echom "' .. log .. '"')
|
cmd('echom "' .. log .. '"')
|
||||||
end
|
|
||||||
M.write(log)
|
|
||||||
end
|
end
|
||||||
|
M.write(log)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.view(l)
|
function M.view(l)
|
||||||
local info = ''
|
local info = ''
|
||||||
local logs = ''
|
local logs = ''
|
||||||
if fn.filereadable(M.file) == 1 then
|
if fn.filereadable(M.file) == 1 then
|
||||||
logs = fn.readfile(M.file, '')
|
logs = fn.readfile(M.file, '')
|
||||||
info = info .. fn.join(fn.filter(logs, 'self._comp(v:val, a:l)'), "\n")
|
info = info .. fn.join(fn.filter(logs, 'self._comp(v:val, a:l)'), '\n')
|
||||||
else
|
else
|
||||||
info = info .. '[ ' .. M.name .. ' ] : logger file ' .. M.file
|
info = info
|
||||||
.. ' does not exists, only log for current process will be shown!'
|
.. '[ '
|
||||||
.. "\n"
|
.. M.name
|
||||||
for key, value in pairs(M.temp) do
|
.. ' ] : logger file '
|
||||||
if M._comp(value, l) == 1 then
|
.. M.file
|
||||||
info = info .. value .. "\n"
|
.. ' does not exists, only log for current process will be shown!'
|
||||||
end
|
.. '\n'
|
||||||
end
|
for key, value in pairs(M.temp) do
|
||||||
|
if M._comp(value, l) == 1 then
|
||||||
|
info = info .. value .. '\n'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return info
|
end
|
||||||
|
return info
|
||||||
end
|
end
|
||||||
|
|
||||||
function M._comp(msg, l)
|
function M._comp(msg, l)
|
||||||
-- if a:msg =~# '\[ ' . self.name . ' \] \[\d\d\:\d\d\:\d\d\] \[ '
|
-- if a:msg =~# '\[ ' . self.name . ' \] \[\d\d\:\d\d\:\d\d\] \[ '
|
||||||
if string.find(msg, M.levels[2]) ~= nil then
|
if string.find(msg, M.levels[2]) ~= nil then
|
||||||
return 1
|
return 1
|
||||||
elseif string.find(msg, M.levels[1]) ~= nil then
|
elseif string.find(msg, M.levels[1]) ~= nil then
|
||||||
if l > 2 then return 0 else return 1 end
|
if l > 2 then
|
||||||
|
return 0
|
||||||
else
|
else
|
||||||
if l > 1 then return 0 else return 1 end
|
return 1
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
if l > 1 then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.set_name(name)
|
function M.set_name(name)
|
||||||
M.name = name
|
M.name = name
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_name()
|
function M.get_name()
|
||||||
return M.name
|
return M.name
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.set_file(file)
|
function M.set_file(file)
|
||||||
M.file = file
|
M.file = file
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
-- License: GPLv3
|
-- License: GPLv3
|
||||||
--=============================================================================
|
--=============================================================================
|
||||||
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local logger = require('spacevim.api').import('logger')
|
local logger = require('spacevim.api').import('logger')
|
||||||
@ -15,9 +14,9 @@ local call = require('spacevim').call
|
|||||||
local echo = require('spacevim').echo
|
local echo = require('spacevim').echo
|
||||||
local fn = nil
|
local fn = nil
|
||||||
if vim.fn == nil then
|
if vim.fn == nil then
|
||||||
fn = require('spacevim').fn
|
fn = require('spacevim').fn
|
||||||
else
|
else
|
||||||
fn = vim.fn
|
fn = vim.fn
|
||||||
end
|
end
|
||||||
|
|
||||||
logger.set_name('SpaceVim')
|
logger.set_name('SpaceVim')
|
||||||
@ -25,115 +24,126 @@ logger.set_level(1)
|
|||||||
logger.set_silent(1)
|
logger.set_silent(1)
|
||||||
logger.set_verbose(1)
|
logger.set_verbose(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function M.info(msg)
|
function M.info(msg)
|
||||||
logger.info(msg)
|
logger.info(msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.warn(msg, ...)
|
function M.warn(msg, ...)
|
||||||
logger.warn(msg, ...)
|
logger.warn(msg, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.error(msg)
|
function M.error(msg)
|
||||||
logger.error(msg)
|
logger.error(msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.debug(msg)
|
function M.debug(msg)
|
||||||
logger.debug(msg)
|
logger.debug(msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setLevel(level)
|
function M.setLevel(level)
|
||||||
logger.set_level(level)
|
logger.set_level(level)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setOutput(file)
|
function M.setOutput(file)
|
||||||
logger.set_file(file)
|
logger.set_file(file)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.viewRuntimeLog()
|
function M.viewRuntimeLog()
|
||||||
local info = "### SpaceVim runtime log :\n\n"
|
local info = '### SpaceVim runtime log :\n\n' .. logger.view(logger.level)
|
||||||
.. logger.view(logger.level)
|
cmd('tabnew')
|
||||||
cmd('tabnew')
|
cmd('setl nobuflisted')
|
||||||
cmd('setl nobuflisted')
|
cmd('nnoremap <buffer><silent> q :tabclose!<CR>')
|
||||||
cmd('nnoremap <buffer><silent> q :tabclose!<CR>')
|
-- put info into buffer
|
||||||
-- put info into buffer
|
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=SpaceVimLog')
|
||||||
cmd('setl filetype=SpaceVimLog')
|
-- M.syntax_extra()
|
||||||
-- M.syntax_extra()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.viewLog(...)
|
function M.viewLog(...)
|
||||||
local argvs={...}
|
local argvs = { ... }
|
||||||
local info = "<details><summary> SpaceVim debug information </summary>\n\n"
|
local info = '<details><summary> SpaceVim debug information </summary>\n\n'
|
||||||
.. "### SpaceVim options :\n\n"
|
.. '### SpaceVim options :\n\n'
|
||||||
.. "```toml\n"
|
.. '```toml\n'
|
||||||
.. fn.join(call('SpaceVim#options#list'), "\n")
|
.. fn.join(call('SpaceVim#options#list'), '\n')
|
||||||
.. "\n```\n"
|
.. '\n```\n'
|
||||||
.. "\n\n"
|
.. '\n\n'
|
||||||
.. "### SpaceVim layers :\n\n"
|
.. '### SpaceVim layers :\n\n'
|
||||||
.. call('SpaceVim#layers#report')
|
.. call('SpaceVim#layers#report')
|
||||||
.. "\n\n"
|
.. '\n\n'
|
||||||
.. "### SpaceVim Health checking :\n\n"
|
.. '### SpaceVim Health checking :\n\n'
|
||||||
.. call('SpaceVim#health#report')
|
.. call('SpaceVim#health#report')
|
||||||
.. "\n\n"
|
.. '\n\n'
|
||||||
.. "### SpaceVim runtime log :\n\n"
|
.. '### SpaceVim runtime log :\n\n'
|
||||||
.. "```log\n"
|
.. '```log\n'
|
||||||
.. logger.view(logger.level)
|
.. logger.view(logger.level)
|
||||||
.. "\n```\n</details>\n\n"
|
.. '\n```\n</details>\n\n'
|
||||||
if argvs ~= nil and #argvs >= 1 then
|
if argvs ~= nil and #argvs >= 1 then
|
||||||
local bang = argvs[1]
|
local bang = argvs[1]
|
||||||
if bang == 1 then
|
if bang == 1 then
|
||||||
cmd('tabnew')
|
cmd('tabnew')
|
||||||
cmd('setl nobuflisted')
|
cmd('setl nobuflisted')
|
||||||
cmd('nnoremap <buffer><silent> q :tabclose!<CR>')
|
cmd('nnoremap <buffer><silent> q :tabclose!<CR>')
|
||||||
-- put info into buffer
|
-- put info into buffer
|
||||||
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=markdown')
|
||||||
else
|
|
||||||
echo(info)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
return info
|
echo(info)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
return info
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.syntax_extra()
|
function M.syntax_extra()
|
||||||
fn.matchadd('ErrorMsg','.*[\\sError\\s\\].*')
|
fn.matchadd('ErrorMsg', '.*[\\sError\\s\\].*')
|
||||||
fn.matchadd('WarningMsg','.*[\\sWarn\\s\\].*')
|
fn.matchadd('WarningMsg', '.*[\\sWarn\\s\\].*')
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.derive(name)
|
function M.derive(name)
|
||||||
local derive = {}
|
local derive = {
|
||||||
derive['origin_name'] = logger.get_name()
|
origin_name = logger.get_name(),
|
||||||
|
_debug_mode = false,
|
||||||
|
derive_name = fn.printf('%' .. fn.strdisplaywidth(logger.get_name()) .. 'S', name),
|
||||||
|
}
|
||||||
|
|
||||||
function derive.info(msg)
|
function derive.info(msg)
|
||||||
logger.set_name(derive.derive_name)
|
logger.set_name(derive.derive_name)
|
||||||
logger.info(msg)
|
logger.info(msg)
|
||||||
logger.set_name(derive.origin_name)
|
logger.set_name(derive.origin_name)
|
||||||
end
|
end
|
||||||
function derive.warn(msg)
|
function derive.warn(msg)
|
||||||
logger.set_name(derive.derive_name)
|
logger.set_name(derive.derive_name)
|
||||||
logger.warn(msg)
|
logger.warn(msg)
|
||||||
logger.set_name(derive.origin_name)
|
logger.set_name(derive.origin_name)
|
||||||
end
|
end
|
||||||
function derive.error(msg)
|
function derive.error(msg)
|
||||||
logger.set_name(derive.derive_name)
|
logger.set_name(derive.derive_name)
|
||||||
logger.error(msg)
|
logger.error(msg)
|
||||||
logger.set_name(derive.origin_name)
|
logger.set_name(derive.origin_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
function derive.debug(msg)
|
function derive.debug(msg)
|
||||||
logger.set_name(derive.derive_name)
|
if derive._debug_mode then
|
||||||
logger.debug(msg)
|
logger.set_name(derive.derive_name)
|
||||||
logger.set_name(derive.origin_name)
|
logger.debug(msg)
|
||||||
|
logger.set_name(derive.origin_name)
|
||||||
end
|
end
|
||||||
derive['derive_name'] = fn.printf('%' .. fn.strdisplaywidth(logger.get_name()) .. 'S', name)
|
end
|
||||||
return derive
|
function derive.start_debug()
|
||||||
|
derive._debug_mode = true
|
||||||
|
end
|
||||||
|
function derive.stop_debug()
|
||||||
|
derive._debug_mode = false
|
||||||
|
end
|
||||||
|
function derive.enabled() -- {{{
|
||||||
|
return derive._debug_mode
|
||||||
|
end
|
||||||
|
-- }}}
|
||||||
|
return derive
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
Reference in New Issue
Block a user