Sha256: b016c3949e5a92ef694d21cfb9d6493d7e6c8993d566219ed917e30bf6f1c8fb

Contents?: true

Size: 1.35 KB

Versions: 12

Compression:

Stored size: 1.35 KB

Contents

# coding: utf-8

# base Splash module
module Splash

  # Splash Loggers module
  module Loggers

    # Web specific logger
    class Web < Splash::Loggers::LoggerTemplate


      # contructor, open log file
      # @return [Splash::Loggers::Web]
      def initialize
        self.level = get_config.loggers[:level]
        @log_file = get_config.loggers[:web][:file]
        @stream = File::open(@log_file, 'a')
        @stream.sync = true
      end

      # log wrapper
      # @param [Hash] options
      # @option options [Symbol] :level defined in Splash::Loggers::LEVEL or Splash::Loggers::ALIAS
      # @option options [String] :message
      # @option options [String] :session a session number
      # write formatted string to log file
      def log(options)
        pid = Process.pid.to_s
        date = DateTime.now.to_s
        level = (ALIAS.keys.include? options[:level])?  ALIAS[options[:level]] : options[:level]
        if @active_levels.include? level then
          unless options[:session].empty? then
            @stream.puts "[#{date}] (#{pid}) (#{options[:session]}) #{alt(options[:level])} : #{options[:message]}"
          else
            @stream.puts "[#{date}] (#{pid}) #{alt(options[:level])} : #{options[:message]}"
          end
        end
      end

      # close log file descriptor
      def close
        @stream.close
      end



    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
prometheus-splash-0.9.1 lib/splash/loggers/web.rb
prometheus-splash-0.9.0 lib/splash/loggers/web.rb
prometheus-splash-0.8.6 lib/splash/loggers/web.rb
prometheus-splash-0.8.5 lib/splash/loggers/web.rb
prometheus-splash-0.8.4 lib/splash/loggers/web.rb
prometheus-splash-0.8.3 lib/splash/loggers/web.rb
prometheus-splash-0.8.2 lib/splash/loggers/web.rb
prometheus-splash-0.8.1 lib/splash/loggers/web.rb
prometheus-splash-0.8.0 lib/splash/loggers/web.rb
prometheus-splash-0.7.0 lib/splash/loggers/web.rb
prometheus-splash-0.6.1 lib/splash/loggers/web.rb
prometheus-splash-0.6.0 lib/splash/loggers/web.rb