lib/tlogger.rb in tlogger-0.5.0 vs lib/tlogger.rb in tlogger-0.6.0

- old
+ new

@@ -12,11 +12,11 @@ # # Singleton object to facilitate tag management # class TloggerConf include Singleton - attr_reader :active_tags, :scoped_tag, :blacklisted_tags, :auto_tag + attr_reader :active_tags, :scoped_tag, :blacklisted_tags, :show_source #GLOBAL_TAG = :global GLOBAL_TAG = "" INT_TAG = :tlogger def initialize @@ -28,25 +28,42 @@ # todo # allow to redirect certain tag to specific output. tag: [<config>] @output_map = {} # if output_map is there, then there should be pre created log file with specific output defined in the map. [<config>] => log_instance @output_log = {} + # show where is the log being printed out. Like auto_tag output + @show_source = false # end todo end - def auto_tag_on - @auto_tag = true + def show_source + @show_source = true end + alias_method :auto_tag_on, :show_source - def auto_tag_off - @auto_tag = false + def hide_source + @show_source = false end + alias_method :auto_tag_off, :hide_source - def is_auto_tag_on? - @auto_tag + def is_show_source? + @show_source end + alias_method :is_auto_tag_on?, :is_show_source? + #def auto_tag_on + # @auto_tag = true + #end + + #def auto_tag_off + # @auto_tag = false + #end + + #def is_auto_tag_on? + # @auto_tag + #end + def activate_tag(tag) @active_tags << tag end def deactivate_tag(tag) @@ -204,20 +221,32 @@ else if TloggerConf.has_scoped_tag? if TloggerConf.is_scoped_tag_active? intDebug("Scoped tag detected") - args[0] = "[#{TloggerConf.scoped_tag}] #{args[0]}" + tag = [] + tag << TloggerConf.scoped_tag + if TloggerConf.instance.is_show_source? + tag << " - " + tag << find_caller + end + args[0] = "[#{tag.join}] #{args[0]}" @tlogger.send(mtd,*args,&block) end elsif TloggerConf.is_auto_tag_on? intDebug("auto_tag is on...") args = tag_class(*args) @tlogger.send(mtd,*args,&block) elsif TloggerConf.is_tag_active?(@tag) intDebug("Tagged output...") - args[0] = "[#{@tag}] #{args[0]}" + tag = [] + tag << @tag + if TloggerConf.instance.is_show_source? + tag << " - " + tag << find_caller + end + args[0] = "[#{tag.join}] #{args[0]}" @tlogger.send(mtd,*args,&block) end end @@ -240,25 +269,38 @@ # end method_missing # private def tag_class(*args) + args[0] = "[#{find_caller}] #{args[0]}" + args + end + # end tag_class() + # + + def find_caller caller.each do |c| next if c =~ /tlogger.rb/ @cal = c break end + + if @cal.nil? or @cal.empty? + @cal = caller[0] + end - if not @cal.nil? and not @cal.empty? - wd = Dir.getwd - @scal = @cal[wd.length..-1] - args[0] = "[#{@scal}] #{args[0]}" + wd = Dir.getwd + indx = @cal =~ /#{wd}/ + if indx != nil + @scal = [] + @scal << @cal[0..indx] + @scal << @cal[indx+wd.length..-1] + @scal.join + else + @cal end - - args - #args[0] = "[#{@cal}] #{args[0]}" end - # end tag_class() + # end find_caller # end # # end class definition #