Class: Dry::Logger::Entry

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/dry/logger/entry.rb

Overview

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clock:, progname:, severity:, tags: EMPTY_ARRAY, message: nil, payload: EMPTY_HASH) ⇒ Entry

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/ParameterLists

Since:

  • 1.0.0



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dry/logger/entry.rb', line 48

def initialize(clock:, progname:, severity:, tags: EMPTY_ARRAY, message: nil,
               payload: EMPTY_HASH)
  @clock = clock
  @progname = progname
  @severity = severity.to_s
  @tags = tags
  @level = LEVELS.fetch(severity.to_s)
  @message = message unless message.is_a?(Exception)
  @exception = message if message.is_a?(Exception)
  @payload = build_payload(payload)
end

Instance Attribute Details

#clockObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



43
44
45
# File 'lib/dry/logger/entry.rb', line 43

def clock
  @clock
end

#exceptionObject (readonly)

Since:

  • 1.0.0



35
36
37
# File 'lib/dry/logger/entry.rb', line 35

def exception
  @exception
end

#levelObject (readonly)

Since:

  • 1.0.0



27
28
29
# File 'lib/dry/logger/entry.rb', line 27

def level
  @level
end

#messageObject (readonly)

Since:

  • 1.0.0



31
32
33
# File 'lib/dry/logger/entry.rb', line 31

def message
  @message
end

#payloadObject (readonly)

Since:

  • 1.0.0



39
40
41
# File 'lib/dry/logger/entry.rb', line 39

def payload
  @payload
end

#prognameObject (readonly)

Since:

  • 1.0.0



15
16
17
# File 'lib/dry/logger/entry.rb', line 15

def progname
  @progname
end

#severityObject (readonly)

Since:

  • 1.0.0



19
20
21
# File 'lib/dry/logger/entry.rb', line 19

def severity
  @severity
end

#tagsObject (readonly)

Since:

  • 1.0.0



23
24
25
# File 'lib/dry/logger/entry.rb', line 23

def tags
  @tags
end

Instance Method Details

#[](name) ⇒ Object

Since:

  • 1.0.0



69
70
71
# File 'lib/dry/logger/entry.rb', line 69

def [](name)
  payload[name]
end

#debug?Boolean

Returns:

  • (Boolean)

Since:

  • 1.0.0



75
76
77
# File 'lib/dry/logger/entry.rb', line 75

def debug?
  level.equal?(DEBUG)
end

#each(&block) ⇒ Object

Since:

  • 1.0.0



63
64
65
# File 'lib/dry/logger/entry.rb', line 63

def each(&block)
  payload.each(&block)
end

#error?Boolean

Returns:

  • (Boolean)

Since:

  • 1.0.0



93
94
95
# File 'lib/dry/logger/entry.rb', line 93

def error?
  level.equal?(ERROR)
end

#exception?Boolean

Returns:

  • (Boolean)

Since:

  • 1.0.0



105
106
107
# File 'lib/dry/logger/entry.rb', line 105

def exception?
  !exception.nil?
end

#fatal?Boolean

Returns:

  • (Boolean)

Since:

  • 1.0.0



99
100
101
# File 'lib/dry/logger/entry.rb', line 99

def fatal?
  level.equal?(FATAL)
end

#filter(filter) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



135
136
137
138
# File 'lib/dry/logger/entry.rb', line 135

def filter(filter)
  @payload = filter.call(payload)
  self
end

#info?Boolean

Returns:

  • (Boolean)

Since:

  • 1.0.0



81
82
83
# File 'lib/dry/logger/entry.rb', line 81

def info?
  level.equal?(INFO)
end

#key?(name) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 1.0.0



111
112
113
# File 'lib/dry/logger/entry.rb', line 111

def key?(name)
  payload.key?(name)
end

#metaObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



123
124
125
# File 'lib/dry/logger/entry.rb', line 123

def meta
  @meta ||= {progname: progname, severity: severity, time: clock.now}
end

#tag?(value) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 1.0.0



117
118
119
# File 'lib/dry/logger/entry.rb', line 117

def tag?(value)
  tags.include?(value)
end

#to_hObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



129
130
131
# File 'lib/dry/logger/entry.rb', line 129

def to_h
  @to_h ||= meta.merge(message: message, **payload)
end

#warn?Boolean

Returns:

  • (Boolean)

Since:

  • 1.0.0



87
88
89
# File 'lib/dry/logger/entry.rb', line 87

def warn?
  level.equal?(WARN)
end