Class: GreenLog::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/green_log/entry.rb

Overview

Represents a structured log entry.

Defined Under Namespace

Classes: Builder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(severity:, message:, context:, data:, exception:) ⇒ Entry

Returns a new instance of Entry.



13
14
15
16
17
18
19
# File 'lib/green_log/entry.rb', line 13

def initialize(severity:, message:, context:, data:, exception:)
  @severity = severity
  @message = message
  @context = context
  @data = data
  @exception = exception
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#dataObject (readonly)

Returns the value of attribute data.



24
25
26
# File 'lib/green_log/entry.rb', line 24

def data
  @data
end

#exceptionObject (readonly)

Returns the value of attribute exception.



25
26
27
# File 'lib/green_log/entry.rb', line 25

def exception
  @exception
end

#messageObject (readonly)

Returns the value of attribute message.



22
23
24
# File 'lib/green_log/entry.rb', line 22

def message
  @message
end

#severityObject (readonly)

Returns the value of attribute severity.



21
22
23
# File 'lib/green_log/entry.rb', line 21

def severity
  @severity
end

Class Method Details

.build(severity, *args, &block) ⇒ Object



40
41
42
# File 'lib/green_log/entry.rb', line 40

def build(severity, *args, &block)
  Builder.new(severity).build(*args, &block)
end

.with(**args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/green_log/entry.rb', line 29

def with(**args)
  args[:severity] = Severity.resolve(
    args.fetch(:severity, Severity::INFO),
  )
  args[:message] ||= nil
  args[:context] = args.fetch(:context, {}).to_loggable_value
  args[:data] = args.fetch(:data, {}).to_loggable_value
  args[:exception] ||= nil
  new(**args)
end

Instance Method Details

#in_context(extra_context) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/green_log/entry.rb', line 46

def in_context(extra_context)
  Entry.new(
    severity: severity,
    message: message,
    context: extra_context.integrate(context).to_loggable_value,
    data: data,
    exception: exception,
  )
end