Commit 9c1edf58 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

logger: option to only log certain channels

parent 70b6ae06
Loading
Loading
Loading
Loading
+26 −14
Original line number Diff line number Diff line
class FnordMetric::Logger

  def self.import(logfile_path)
    expire = FnordMetric.options[:event_queue_ttl]
    redis  = Redis.new
 
    if @opts[:channels]
      @opts[:channels] = @opts[:channels].map(&:to_s) 
    end

    dump_file = File.open(logfile_path, 'r')
    num_lines = %x{wc -l #{logfile_path}}.to_i
    puts "importing #{num_lines} events..."

    dump_file.each_with_log(num_lines) do |line, ind|
      (8**64).to_s(36).tap do |uuid|
        redis.set    "fnordmetric-event-#{uuid}", line
        redis.lpush  "fnordmetric-queue"        , uuid
        redis.expire "fnordmetric-event-#{uuid}", expire
      end
    end
  end

  def initialize(opts)
    @opts = opts
    opts.fetch(:file)
@@ -25,28 +46,19 @@ class FnordMetric::Logger
    listener = Thread.new do  
      backend = FnordMetric.backend
      backend.subscribe do |event|
        events << event
        events << event if log_channel?(event["_channel"])
      end
    end

    FnordMetric.log "logging to #{logfile_path}"
  end

  def self.import(logfile_path)
    expire = FnordMetric.options[:event_queue_ttl]
    redis  = Redis.new

    dump_file = File.open(logfile_path, 'r')
    num_lines = %x{wc -l #{logfile_path}}.to_i
    puts "importing #{num_lines} events..."
private

    dump_file.each_with_log(num_lines) do |line, ind|
      (8**64).to_s(36).tap do |uuid|
        redis.set    "fnordmetric-event-#{uuid}", line
        redis.lpush  "fnordmetric-queue"        , uuid
        redis.expire "fnordmetric-event-#{uuid}", expire
      end
    end
  def log_channel?(channel)
    return !!@opts[:channels] if !channel
    @opts[:channels].include?(channel.to_s)
  end

end
 No newline at end of file