Sha256: c5ac23645b2d91a4c860337ea7d51001f84d428c82f1f1ba32eae0547cf7c44a

Contents?: true

Size: 793 Bytes

Versions: 9

Compression:

Stored size: 793 Bytes

Contents

# frozen_string_literal: true

module RubySmart
  module SimpleLogger
    module Extensions
      module Logs
        # returns the logdev logs
        # @return [Array]
        def logs
          return [] unless logdev.respond_to?(:logs)
          logdev.logs
        end

        # transforms the logs-array into a hash of logs, grouped by level (:error, :success, ...)
        # @return [Hash] logs
        def logs_to_h
          logs.reduce({}) do |m, log|
            m[log[0]] ||= []
            m[log[0]] << log[2]
            m
          end
        end

        # returns a hash with total amounts per logged type (key)
        # @return [Hash]
        def log_stats
          logs_to_h.reduce({}) { |m, (sev, logs)| m[sev] = logs.count; m }
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruby_smart-simple_logger-1.5.3 lib/ruby_smart/simple_logger/extensions/logs.rb
ruby_smart-simple_logger-1.5.2 lib/ruby_smart/simple_logger/extensions/logs.rb
ruby_smart-simple_logger-1.5.1 lib/ruby_smart/simple_logger/extensions/logs.rb
ruby_smart-simple_logger-1.5.0 lib/ruby_smart/simple_logger/extensions/logs.rb
ruby_smart-simple_logger-1.4.0 lib/ruby_smart/simple_logger/extensions/logs.rb
ruby_smart-simple_logger-1.3.0 lib/ruby_smart/simple_logger/extensions/logs.rb
ruby_smart-simple_logger-1.2.2 lib/ruby_smart/simple_logger/extensions/logs.rb
ruby_smart-simple_logger-1.2.1 lib/ruby_smart/simple_logger/extensions/logs.rb
ruby_smart-simple_logger-1.2.0 lib/ruby_smart/simple_logger/extensions/logs.rb