File: core.rb

package info (click to toggle)
ruby-dry-logger 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 156 kB
  • sloc: ruby: 802; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 848 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

require "dry/logger/constants"

module Dry
  module Logger
    module Backends
      module Core
        # Return a proc used by the log? predicate
        #
        # @since 1.0.0
        # @api private
        attr_reader :log_if

        # Set a predicate proc that checks if an entry should be logged by a given backend
        #
        # The predicate will receive {Entry} as its argument and should return true/false
        #
        # @param [Proc, #to_proc] spec A proc-like object
        # @since 1.0.0
        # @api public
        def log_if=(spec)
          @log_if = spec&.to_proc
        end

        # @since 1.0.0
        # @api private
        def log?(entry)
          if log_if
            log_if.call(entry)
          else
            true
          end
        end
      end
    end
  end
end