Last active
November 6, 2015 21:37
-
-
Save nfarrar/951c0c5a8908430132d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Author: Nathan Farrar <[email protected]> | |
" Website: https://crunk.io/dotfiles/ | |
" Description: vlog plugin {{{ | |
" | |
" A light weight message logging interface for debugging vim configurations. | |
" Messages are saved to a list rather than a file to improve performance | |
" times. | |
" | |
" - Echo, echom and echoerr seem highly unreliable to me. Various plugins | |
" call :redraw, which flushes messages and we never see them. | |
" | |
" - It's not good practice to leave 'echo' commands sitting around in | |
" plugins - depending on the user's configuration they force 'prompt here | |
" to continue' messages, which makes the messages feature unusable for | |
" debugging output, imho. | |
" | |
" TODO: | |
" | |
" - log messages to a 'toggableable' buffer | |
" - capture messages from echo, echom & echoerr? | |
" - hook 'source' commands and inject debugging messages? | |
" | |
" Bookmarks: | |
" | |
" - https://stackoverflow.com/questions/2573021/how-to-redirect-ex-command-output-into-current-buffer-or-file | |
" - https://github.com/mbbill/echofunc | |
" - https://gist.github.com/mattn/715256 | |
" - http://cowsthatgomoo.blogspot.com/2014/12/how-to-echo-color-from-vim-using.html | |
" - https://github.com/AD7six/vim-activity-log | |
" - https://github.com/taku-o/vim-logging/blob/master/plugin/logging.vim | |
" | |
" }}} | |
if exists('g:loaded_vlog') || &cp | |
finish | |
endif | |
let g:loaded_vlog = 1 | |
" List of log messages. | |
let s:vlog_messages = [] | |
" Bind log level names to ints. | |
let s:vlog_levels = { | |
\ 'ERROR': 4, | |
\ 'WARN': 3, | |
\ 'INFO': 2, | |
\ 'DEBUG': 1 | |
\ } | |
" Set the default log level. | |
if ! empty($VIM_VLOG_LEVEL) && has_key(s:vlog_levels, $VIM_VLOG_LEVEL) | |
let s:vlog_level = $VIM_VLOG_LEVEL | |
else | |
let s:vlog_level = 'DEBUG' | |
endif | |
function! s:timestamp() " {{{ | |
return strftime("%Y.%m.%d_%H:%M:%S") | |
endfunction " }}} | |
function! s:vlog(msg, msg_lvl) " {{{ | |
if a:msg_lvl >= s:vlog_levels[s:vlog_level] | |
call add(s:vlog_messages, s:timestamp() . ' ' . a:msg) | |
endif | |
endfunction " }}} | |
function s:vlog_echo(msg) " {{{ | |
" execute! printf '\x1b[31m;%s;[x1b\0m' | |
" echo printf("\x1b[31m%s[\x1b[0m", a:msg) | |
echo a:msg | |
endfunction " }}} | |
function! vlog#error(msg) " {{{ | |
call s:vlog(a:msg, s:vlog_levels.ERROR) | |
endfunction " }}} | |
function! vlog#warn(msg) " {{{ | |
call s:vlog(a:msg, s:vlog_levels.WARN) | |
endfunction " }}} | |
function! vlog#info(msg) " {{{ | |
call s:vlog(a:msg, s:vlog_levels.INFO) | |
endfunction " }}} | |
function! vlog#debug(msg) " {{{ | |
call s:vlog(a:msg, s:vlog_levels.DEBUG) | |
endfunction " }}} | |
function! vlog#display() " {{{ | |
for msg in s:vlog_messages | |
call s:vlog_echo(msg) | |
endfor | |
endfunction " }}} | |
function! vlog#clear() " {{{ | |
let s:vlog_messages = [] | |
endfunction " }}} | |
" if has('autocmd') | |
" augroup | |
" autocmd! | |
" autocmd SourcePre call vlog#debug('sourced file ' . a:file) | |
" augroup END | |
" endif | |
" call vlog#debug('sourced '. expand('%:p') | |
call vlog#debug('test') | |
command! VlogDisplay :call vlog#display() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment