Class: TTY::Logger::Handlers::Raven

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/tty/logger/handlers/raven.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output: $stderr, formatter: nil, config: nil, level: nil, styles: {}) ⇒ Raven

Returns a new instance of Raven.



13
14
15
16
17
18
19
# File 'lib/tty/logger/handlers/raven.rb', line 13

def initialize(
  output: $stderr, formatter: nil, config: nil, level: nil, styles: {}
)
  @config = config
  @level = level || @config.level
  @mutex = Mutex.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/tty/logger/handlers/raven.rb', line 11

def config
  @config
end

#levelObject (readonly)

Returns the value of attribute level.



11
12
13
# File 'lib/tty/logger/handlers/raven.rb', line 11

def level
  @level
end

Instance Method Details

#call(event) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tty/logger/handlers/raven.rb', line 22

def call(event)
  @mutex.lock

  data = {}

  event..each do |meta|
    case meta
    when :file
      data[:path] = format_filepath(event)
    end
  end

  unless event.backtrace.empty?
    data[:type] = event.message.first&.class&.name
    data[:value] = event.message.first&.message
  end

  data.merge!(event.fields) unless event.fields.empty?

  ::Raven.breadcrumbs.record do |crumb|
    crumb.level = event.[:level].to_s
    crumb.category = 'logger'
    crumb.message = event.message.join(' ')
    crumb.timestamp = event.[:time].to_i
    crumb.type = event.backtrace.empty? ? 'default' : 'error'
    crumb.data = data
  end
ensure
  @mutex.unlock
end