Sha256: 06f4475d8f502e39b07cf2228c779ac20da41e684fc0c6dc29812b340832492b

Contents?: true

Size: 1.37 KB

Versions: 12

Compression:

Stored size: 1.37 KB

Contents

# coding: utf-8

# base Splash module
module Splash

  # Splash Loggers module
  module Loggers

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


      # contructor, open log file
      # @return [Splash::Loggers::Daemon]
      def initialize
        self.level = get_config.loggers[:level]
        @log_file = get_config.loggers[:daemon][: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/daemon.rb
prometheus-splash-0.9.0 lib/splash/loggers/daemon.rb
prometheus-splash-0.8.6 lib/splash/loggers/daemon.rb
prometheus-splash-0.8.5 lib/splash/loggers/daemon.rb
prometheus-splash-0.8.4 lib/splash/loggers/daemon.rb
prometheus-splash-0.8.3 lib/splash/loggers/daemon.rb
prometheus-splash-0.8.2 lib/splash/loggers/daemon.rb
prometheus-splash-0.8.1 lib/splash/loggers/daemon.rb
prometheus-splash-0.8.0 lib/splash/loggers/daemon.rb
prometheus-splash-0.7.0 lib/splash/loggers/daemon.rb
prometheus-splash-0.6.1 lib/splash/loggers/daemon.rb
prometheus-splash-0.6.0 lib/splash/loggers/daemon.rb