Sha256: caa0fd5126aca8c305a562f1544bb0035d6d4df8e7cdb7359abc688829378cbd

Contents?: true

Size: 1.41 KB

Versions: 7

Compression:

Stored size: 1.41 KB

Contents

# Contains methods specific to logging (initializing the log file, applying the log level, applying the log format, etc.)
module ProfileIt
  class Agent
    module Logging
      def log_path
        "#{environment.root}/log"
      end
      
      def init_logger
        @log_file = "#{log_path}/profile_it.log"
        begin 
          @logger = Logger.new(@log_file) 
          @logger.level = log_level
          apply_log_format
        rescue Exception => e
          @logger = Logger.new(STDOUT)
          apply_log_format
          @logger.error "Unable to access log file: #{e.message}"
        end
        @logger
      end

      def apply_log_format
        def logger.format_message(severity, timestamp, progname, msg)
          # since STDOUT isn't exclusive like the profile_it.log file, apply a prefix.
          prefix = @logdev.dev == STDOUT ? "profile_it " : ''
          prefix + "[#{timestamp.strftime("%m/%d/%y %H:%M:%S %z")} #{Socket.gethostname} (#{$$})] #{severity} : #{msg}\n"
        end
      end

      def log_level
        case config.settings['log_level'].downcase
          when "debug" then Logger::DEBUG
          when "info" then Logger::INFO
          when "warn" then Logger::WARN
          when "error" then Logger::ERROR
          when "fatal" then Logger::FATAL
          else Logger::INFO
        end
      end
    end # module Logging
    include Logging
  end # class Agent
end # moudle ProfileIt

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
profile_it-0.2.9 lib/profile_it/agent/logging.rb
profile_it-0.2.8.1 lib/profile_it/agent/logging.rb
profile_it-0.2.8 lib/profile_it/agent/logging.rb
profile_it-0.2.7 lib/profile_it/agent/logging.rb
profile_it-0.2.6 lib/profile_it/agent/logging.rb
profile_it-0.2.5 lib/profile_it/agent/logging.rb
profile_it-0.2.4 lib/profile_it/agent/logging.rb