Skip to content

Commit 8ad4eef

Browse files
author
Anton Astashov
committed
Merge pull request #55 from stephenprater/efficient_logging
efficient logging
2 parents 6ce819c + 97702be commit 8ad4eef

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

bin/ruby_debugger.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ def have_unclosed_tag?(output)
168168
def log(string)
169169
if @params[:debug_mode] == '1'
170170
File.open(@params[:logger_file], 'a') do |f|
171-
f.puts 'Ruby_debugger.rb, ' + Time.now.strftime("%H:%M:%S") + ': ' + string
171+
# match vim redir style new lines, rather than trailing
172+
f << "\nRuby_debugger.rb, #{Time.now.strftime("%H:%M:%S")} : #{string.chomp}"
172173
end
173174
end
174175
end

src/ruby_debugger/logger.vim

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ endfunction
1111

1212

1313
" Log datetime and then message. It logs only if debug mode is enabled
14-
" TODO: Now to add one line to the log file, it read whole file to memory, add
15-
" one line and write all that stuff back to file. When log file is large, it
16-
" affects performance very much. Need to find way to write only to the end of
17-
" file (preferably - crossplatform way. Maybe Ruby?)
18-
function! s:Logger.put(string)
14+
" TODO It outputs a bunch of spaces at the front of the entry - fix that.
15+
function! s:Logger.put(string) dict
1916
if g:ruby_debugger_debug_mode
20-
let file = readfile(self.file)
2117
let string = 'Vim plugin, ' . strftime("%H:%M:%S") . ': ' . a:string
22-
call add(file, string)
23-
call writefile(file, self.file)
18+
exec 'redir >> ' . g:RubyDebugger.logger.file
19+
silent call s:Logger.silent_echo(s:strip(string))
20+
exec 'redir END'
2421
endif
2522
endfunction
2623

27-
" *** Logger class (end)
28-
24+
function! s:Logger.silent_echo(string)
25+
echo a:string
26+
endfunction
2927

28+
" *** Logger class (end)
29+
"
30+
"

0 commit comments

Comments
 (0)