Class: TwitterFriendly::TFLogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Includes:
Logging
Defined in:
lib/twitter_friendly/log_subscriber.rb

Instance Method Summary collapse

Methods included from Logging

logger, logger=, #truncated_payload

Instance Method Details

#collect(event) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/twitter_friendly/log_subscriber.rb', line 59

def collect(event)
  debug do
    payload = event.payload
    payload.delete(:name)
    operation = payload.delete(:operation)
    name = "  TW::#{operation.capitalize} #{payload[:args].last[:super_operation]} in #{payload[:args][0]} (#{event.duration.round(1)}ms)"
    name = color(name, BLUE, true)
    "  #{name}"
  end
end

#complete_processing(event) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/twitter_friendly/log_subscriber.rb', line 46

def complete_processing(event)
  info do
    payload = event.payload
    operation = payload.delete(:operation)

    if payload.empty?
      "TF::Completed #{operation} in #{event.duration.round(1)}ms"
    else
      "TF::Completed #{operation} in #{event.duration.round(1)}ms #{truncated_payload(payload)}"
    end
  end
end

#start_processing(event) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/twitter_friendly/log_subscriber.rb', line 33

def start_processing(event)
  info do
    payload = event.payload
    operation = payload.delete(:operation)

    if payload[:super_operation]
      "TF::Started #{operation} in #{payload[:super_operation][0]} at #{Time.now}"
    else
      "TF::Started #{operation} at #{Time.now}"
    end
  end
end

#twitter_friendly_any(event) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/twitter_friendly/log_subscriber.rb', line 70

def twitter_friendly_any(event)
  debug do
    payload = event.payload
    payload.delete(:name)
    operation = payload.delete(:operation).capitalize
    args = payload[:args]
    method_name = args.shift

    name = "  TW::#{operation} #{method_name} (#{event.duration.round(1)}ms)"
    c = (%i(Encode Decode).include?(operation.to_sym)) ? YELLOW : CYAN
    name = color(name, c, true)

    if args.size == 1 && args[0].is_a?(Hash) && args[0].empty?
      "  #{name}"
    else
      "  #{name} #{args[1]}"
    end
  end
end