Skip to content

Commit 6410215

Browse files
committed
Improve logger
1 parent 93337f3 commit 6410215

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

autoload/fern/logger.vim

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
let s:Later = vital#fern#import('Async.Later')
2+
let s:LEVEL_HIGHLIGHT = {
3+
\ 'DEBUG': 'Comment',
4+
\ 'INFO': 'Special',
5+
\ 'WARN': 'WarningMsg',
6+
\ 'ERROR': 'ErrorMsg',
7+
\}
28

39
function! fern#logger#debug(...) abort
410
if g:fern#loglevel > g:fern#logger#DEBUG
@@ -31,20 +37,23 @@ endfunction
3137
function! s:log(level, ...) abort
3238
let content = s:format(a:level, a:000)
3339
if g:fern#logfile is# v:null
34-
call s:Later.call({ -> s:echomsg(content) })
40+
let hl = get(s:LEVEL_HIGHLIGHT, a:level, 'None')
41+
call s:Later.call({ -> s:echomsg(hl, content) })
3542
else
3643
call s:Later.call({ -> s:writefile(content) })
3744
endif
3845
endfunction
3946

40-
function! s:echomsg(content) abort
47+
function! s:echomsg(hl, content) abort
4148
let more = &more
4249
try
4350
set nomore
51+
execute printf('echohl %s', a:hl)
4452
for line in a:content
4553
echomsg '[fern] ' . line | redraw | echo
4654
endfor
4755
finally
56+
echohl None
4857
let &more = more
4958
endtry
5059
endfunction
@@ -65,7 +74,7 @@ endfunction
6574

6675
function! s:format(level, args) abort
6776
let m = join(map(copy(a:args), { _, v -> type(v) is# v:t_string ? v : string(v) }))
68-
return map(split(m, '\n'), { -> printf("%-5S:\t%s", a:level, v:val) })
77+
return map(split(m, '\n'), { -> printf("%-5S: %s", a:level, v:val) })
6978
endfunction
7079

7180
let g:fern#logger#DEBUG = 0

0 commit comments

Comments
 (0)