Sha256: cd0dbcf89e2e5721d2365c978a8e58547ce36873650d67e2914a55d3136e4076

Contents?: true

Size: 1.67 KB

Versions: 6

Compression:

Stored size: 1.67 KB

Contents

module Rackamole::Store
  class Log
            
    # Stores mole information to a log file or dump it to the console. All
    # available mole info will dumped to the logger.
    #
    # === Params:
    # file_name :: Specifies a file to send the logs to. By default mole info
    # will be sent out to stdout.
    def initialize( file_name=$stdout )
      @logger = Rackamole::Logger.new( :log_file => file_name )
    end
    
    # Dump mole info to logger
    #
    # === Params:
    # attrs :: The available moled information for a given feature
    def mole( attrs )
      return if attrs.empty?
              
      display_head( attrs )
      display_commons( attrs )          
    rescue => mole_boom
      log.error "MOLE STORE CRAPPED OUT -- #{mole_boom}"
      log.error mole_boom.backtrace.join( "\n   " )        
    end
       
    # =======================================================================
    private

      # dump moled info to log
      def display_commons( args )
        args.each do |k,v|
          display_info( k.to_s.capitalize, v.inspect )
        end
      end
      
      # retrieves logger instance
      def log
        @logger
      end
      
      # Console layout spacer
      def spacer() 20; end

      # Display mole type
      def display_head( args )
        log.info "-"*100
        log.info case args[:type]
          when Rackamole.feature 
            "FEATURE"
          when Rackamole.fault
            "FAULT"
          when Rackamole.perf
            "PERFORMANCE"
        end
      end
      
      # Output formating...         
      def display_info( key, value )
        log.info "%-#{spacer}s : %s" % [key, value]
      end        
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rackamole-0.4.1 lib/rackamole/store/log.rb
rackamole-0.4.0 lib/rackamole/store/log.rb
rackamole-0.3.9 lib/rackamole/store/log.rb
rackamole-0.3.8 lib/rackamole/store/log.rb
rackamole-0.3.7 lib/rackamole/store/log.rb
rackamole-0.3.6 lib/rackamole/store/log.rb