https://svn.lrde.epita.fr/svn/lrdetools/trunk
Index: ChangeLog
from Nicolas Pouillard <ertai(a)lrde.epita.fr>
Vcs::Logger: Better handling of multiline messages.
* vcs/lib/vcs/app.rb: Make the backtrace appear as error but just when
debug is on.
* vcs/lib/vcs/vcs.rb (Logger): Put the same header before each line of
the message. Cache the coloring to speed up the logger.
app.rb | 4 ++--
vcs.rb | 13 +++++++++++--
2 files changed, 13 insertions(+), 4 deletions(-)
Index: vcs/lib/vcs/app.rb
--- vcs/lib/vcs/app.rb (revision 250)
+++ vcs/lib/vcs/app.rb (working copy)
@@ -112,10 +112,10 @@
raise ex
rescue Exception => ex
vcs.call_handlers unless vcs.nil?
- logger.debug { raise ex }
err = ex.to_s.sub(/\.$/, '')
+ logger.debug { err = ex.long_pp ; "Backtrace enabled:" }
err = ex.inspect if err.empty?
- logger.error err
+ logger.error { err }
end
end
Index: vcs/lib/vcs/vcs.rb
--- vcs/lib/vcs/vcs.rb (revision 250)
+++ vcs/lib/vcs/vcs.rb (working copy)
@@ -62,12 +62,21 @@
@color = false
end
+ def header ( progname, severity )
+ @@headers[[progname, severity]] ||= [
+ '[', 'vcs', ']', ' ', progname, severity,
':', ' '
+ ].compact.map { |x| stylize x }.join
+ end
+
def format_message(severity, timestamp, msg, progname)
progname += ': ' unless progname.nil? or progname.empty?
- "#{stylize('[')}#{stylize('vcs')}#{stylize(']')}
" +
- "#{progname}#{stylize(severity)}#{stylize(':')} #{msg}\n"
+ msg.inject([]) do |accu, line|
+ accu << header(progname, severity) << line.chomp <<
"\n"
+ end.join
end
+ @@headers ||= {}
+
@@style =
{
:vcs => [:cyan],