# Author:: Nicolas Pouillard . # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved. # License:: LGPL # $Id: /w/fey/uttk/trunk/lib/uttk/logger/to_uttk_log.rb 24396 2006-07-10T08:23:37.784417Z ertai $ module Uttk class Logger # These extensions add to any object, a proper way # to inject an object in a result like Logger. # # Example: # # include Uttk # anObject.to_uttk_log(Logger.new(Dumper::Yaml.new(STDERR))) # module ToUttkLog class ::Object def to_uttk_log ( log ) log.new_leaf(self) end def to_uttk_log_with_key ( key, log ) log.new_node key do log << self end end end # class ::Object class ::Hash def to_uttk_log ( log ) each do |k, v| next if k == :strategy log[k] = v end end def to_uttk_log_with_key ( key, log, opts=nil ) if has_key? :strategy opts = (opts || {}).merge(:type => self[:strategy]) end log.new_node key, opts do log << self end end end # class ::Hash ::OHash.class_eval do def to_uttk_log_with_key ( key, log ) super key, log, :ordered => true end end # class ::OHash class ::Array # WARNING: Do not implement Array#to_uttk_log it doesn't make sense. def to_uttk_log_with_key ( key, log ) unless ! empty? and all? { |x| x.is_a? Hash and x.size == 1 } return super end log.new_node key, :ordered => true do each do |x| k, v = x.to_a.first log[k] = v end end end end # class ::Array class ::Exception def to_uttk_log ( log ) if log.severity_level <= Severity::DEBUG long_pp.to_uttk_log(log) elsif log.severity_level <= Severity::VERBOSE_INFO short_pp.to_uttk_log(log) else tiny_pp.to_uttk_log(log) end end end # class ::Exception class ::Benchmark::Tms def to_uttk_log ( log ) if @label.empty? benchmark_tms_to_uttk_log(log) else log.new_node(@label) { benchmark_tms_to_uttk_log(log) } end end def benchmark_tms_to_uttk_log(log) log[:cutime] = @cutime log[:cstime] = @cstime log[:utime] = @utime log[:stime] = @stime log[:total] = @total log[:real] = @real end private :benchmark_tms_to_uttk_log end # class ::Benchmark::Tms end # module ToUttkLog end # class Logger end # module Uttk