Permalink
Browse files

Add timestamps to log. Log channel traffic.

  • Loading branch information...
1 parent ae434ce commit 13c294395965d4aae94bb9abd63cc5a72cd0f0f4 @airblade committed Apr 27, 2016
Showing with 32 additions and 5 deletions.
  1. +1 −1 .gitignore
  2. +31 −4 autoload/gitgutter/debug.vim
View
@@ -1,5 +1,5 @@
/doc/tags
/misc
/test/*.actual
-gitgutter.log
+*.log
@@ -1,4 +1,8 @@
-let s:log_file = expand('<sfile>:p:h:h:h').'/'.'gitgutter.log'
+let s:plugin_dir = expand('<sfile>:p:h:h:h').'/'
+let s:log_file = s:plugin_dir.'gitgutter.log'
+let s:channel_log = s:plugin_dir.'channel.log'
+let s:new_log_session = 1
+
function! gitgutter#debug#debug()
" Open a scratch buffer
@@ -75,16 +79,39 @@ endfunction
" assumes optional args are calling function's optional args
function! gitgutter#debug#log(message, ...)
if g:gitgutter_log
+ if s:new_log_session && gitgutter#async#available()
+ call ch_logfile(s:channel_log, 'w')
+ endif
+
execute 'redir >> '.s:log_file
+ if s:new_log_session
+ let s:start = reltime()
+ silent echo "\n==== start log session ===="
+ endif
+
+ let elapsed = reltimestr(reltime(s:start)).' '
+ silent echo ''
" callers excluding this function
- silent echo "\n".expand('<sfile>')[:-22].':'
- silent echo type(a:message) == 1 ? join(split(a:message, '\n'),"\n") : a:message
+ silent echo elapsed.expand('<sfile>')[:-22].':'
+ silent echo elapsed.s:format_for_log(a:message)
if a:0 && !empty(a:1)
for msg in a:000
- silent echo type(msg) == 1 ? join(split(msg, '\n'),"\n") : msg
+ silent echo elapsed.s:format_for_log(msg)
endfor
endif
redir END
+
+ let s:new_log_session = 0
+ endif
+endfunction
+
+function! s:format_for_log(data)
+ if type(a:data) == 1
+ return join(split(a:data,'\n'),"\n")
+ elseif type(a:data) == 3
+ return '['.join(a:data,"\n").']'
+ else
+ return a:data
endif
endfunction

0 comments on commit 13c2943

Please sign in to comment.