Sha256: 9755fdde10dd2c827ea1b0e9d94bb00390d2c1998c95559c17f02d1a2f986f0e

Contents?: true

Size: 749 Bytes

Versions: 1

Compression:

Stored size: 749 Bytes

Contents

module Services
  module Logger
    class Redis
      def initialize(redis, key = 'logs')
        @redis, @key = redis, key
      end

      def log(message, meta = {}, severity = :info)
        value = {
          time:     Time.now.to_i,
          message:  message,
          severity: severity,
          meta:     meta
        }
        @redis.lpush @key, value.to_json
      end

      def size
        @redis.llen @key
      end

      def fetch
        @redis.lrange(@key, 0, -1).map do |json|
          JSON.load json
        end
      end

      def clear
        @redis.multi do
          @redis.lrange @key, 0, -1
          @redis.del @key
        end.first.map do |json|
          JSON.load json
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
services-1.1.0 lib/services/logger/redis.rb