Skip to content

Commit 4bed1da

Browse files
committed
Add simple logging.
1 parent 52d1167 commit 4bed1da

6 files changed

Lines changed: 28 additions & 3 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/doc/tags
22
/misc
33
/test/*.actual
4+
gitgutter.log
5+

autoload/gitgutter.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function! gitgutter#process_buffer(bufnr, realtime)
2525
endif
2626
endif
2727
catch /diff failed/
28+
call gitgutter#debug#log('diff failed')
2829
call gitgutter#hunk#reset()
2930
endtry
3031
else
@@ -34,6 +35,8 @@ endfunction
3435

3536

3637
function! gitgutter#handle_diff_job(job_id, data, event)
38+
call gitgutter#debug#log('job_id: '.a:job_id.', event: '.a:event)
39+
3740
if a:event == 'stdout'
3841
" a:data is a list
3942
call gitgutter#utility#job_output_received(a:job_id, 'stdout')
@@ -56,6 +59,8 @@ endfunction
5659

5760

5861
function! gitgutter#handle_diff(diff)
62+
call gitgutter#debug#log(a:diff)
63+
5964
call setbufvar(gitgutter#utility#bufnr(), 'gitgutter_tracked', 1)
6065

6166
call gitgutter#hunk#set_hunks(gitgutter#diff#parse_diff(a:diff))

autoload/gitgutter/debug.vim

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
let s:log_file = expand('<sfile>:p:h:h:h').'/'.'gitgutter.log'
2+
13
function! gitgutter#debug#debug()
24
" Open a scratch buffer
35
vsplit __GitGutter_Debug__
@@ -70,8 +72,19 @@ function! gitgutter#debug#output(text)
7072
call append(line('$'), a:text)
7173
endfunction
7274

73-
function! gitgutter#debug#log(message)
74-
let msg = type(a:message) == 1 ? split(a:message, '\n') : a:message
75-
call writefile(msg, 'gitgutter.log', 'a')
75+
" assumes optional args are calling function's optional args
76+
function! gitgutter#debug#log(message, ...)
77+
if g:gitgutter_log
78+
execute 'redir >> '.s:log_file
79+
" callers excluding this function
80+
silent echo "\n".expand('<sfile>')[:-22].':'
81+
silent echo type(a:message) == 1 ? join(split(a:message, '\n'),"\n") : a:message
82+
if a:0 && !empty(a:1)
83+
for msg in a:000
84+
silent echo type(msg) == 1 ? join(split(msg, '\n'),"\n") : msg
85+
endfor
86+
endif
87+
redir END
88+
endif
7689
endfunction
7790

autoload/gitgutter/diff.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ function! gitgutter#diff#run_diff(realtime, preserve_full_diff)
134134
\ 'on_stderr': function('gitgutter#handle_diff_job'),
135135
\ 'on_exit': function('gitgutter#handle_diff_job')
136136
\ })
137+
call gitgutter#debug#log('[job_id: '.job_id.'] '.cmd)
137138
if job_id < 1
138139
throw 'diff failed'
139140
endif
141+
140142
call gitgutter#utility#pending_job(job_id)
141143
return 'async'
142144
else

autoload/gitgutter/utility.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ function! gitgutter#utility#using_xolox_shell()
121121
endfunction
122122

123123
function! gitgutter#utility#system(cmd, ...)
124+
call gitgutter#debug#log(a:cmd, a:000)
125+
124126
if gitgutter#utility#using_xolox_shell()
125127
let options = {'command': a:cmd, 'check': 0}
126128
if a:0 > 0

plugin/gitgutter.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ call s:set('g:gitgutter_diff_base', '')
5050
call s:set('g:gitgutter_map_keys', 1)
5151
call s:set('g:gitgutter_avoid_cmd_prompt_on_windows', 1)
5252
call s:set('g:gitgutter_async', 1)
53+
call s:set('g:gitgutter_log', 0)
5354

5455
call gitgutter#highlight#define_sign_column_highlight()
5556
call gitgutter#highlight#define_highlights()

0 commit comments

Comments
 (0)