Class: Binnacle::Client
- Inherits:
-
Object
- Object
- Binnacle::Client
- Defined in:
- lib/binnacle/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#logging_channel_id ⇒ Object
Returns the value of attribute logging_channel_id.
-
#ready ⇒ Object
writeonly
Sets the attribute ready.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
Instance Method Summary collapse
- #broadcast(channel_id, event_name, json) ⇒ Object
- #close ⇒ Object
- #events(channel, date, start_hour, end_hour, lines) ⇒ Object
-
#formatter ⇒ Object
Ruby Logger Implementation.
-
#initialize(api_key = nil, api_secret = nil, endpoint = nil, logging_channel_id = nil) ⇒ Client
constructor
A new instance of Client.
- #log_http_event(data) ⇒ Object
- #log_rails_event(data) ⇒ Object
- #ready? ⇒ Boolean
- #recents(lines, since, channel) ⇒ Object
- #report_exception(exception, env, asynch = true) ⇒ Object
- #session_and_client_ids ⇒ Object
- #signal(channel_id, event_name, client_id, session_id, log_level, environment = Event.rails_env, tags = [], json = {}, asynch = false) ⇒ Object
- #signal_asynch(channel_id, event_name, client_id = '', session_id = '', log_level = 'INFO', environment = Event.rails_env, tags = [], json = {}) ⇒ Object
- #write(event) ⇒ Object
Constructor Details
#initialize(api_key = nil, api_secret = nil, endpoint = nil, logging_channel_id = nil) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/binnacle/client.rb', line 16 def initialize(api_key = nil, api_secret = nil, endpoint = nil, logging_channel_id = nil) self.api_key = api_key || Binnacle.configuration.api_key self.api_secret = api_secret || Binnacle.configuration.api_secret if endpoint self.connection = Connection.new(self.api_key, self.api_secret, Binnacle.configuration.build_url(endpoint)) else self.connection = Connection.new(self.api_key, self.api_secret) end self.logging_channel_id = logging_channel_id || Binnacle.configuration.logging_channel self.client_id = "" self.session_id = "" @formatter = Binnacle::Logging::Formatter.new(self) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/binnacle/client.rb', line 9 def api_key @api_key end |
#api_secret ⇒ Object
Returns the value of attribute api_secret.
9 10 11 |
# File 'lib/binnacle/client.rb', line 9 def api_secret @api_secret end |
#client_id ⇒ Object
Returns the value of attribute client_id.
12 13 14 |
# File 'lib/binnacle/client.rb', line 12 def client_id @client_id end |
#connection ⇒ Object
Returns the value of attribute connection.
10 11 12 |
# File 'lib/binnacle/client.rb', line 10 def connection @connection end |
#logging_channel_id ⇒ Object
Returns the value of attribute logging_channel_id.
11 12 13 |
# File 'lib/binnacle/client.rb', line 11 def logging_channel_id @logging_channel_id end |
#ready=(value) ⇒ Object (writeonly)
Sets the attribute ready
14 15 16 |
# File 'lib/binnacle/client.rb', line 14 def ready=(value) @ready = value end |
#session_id ⇒ Object
Returns the value of attribute session_id.
13 14 15 |
# File 'lib/binnacle/client.rb', line 13 def session_id @session_id end |
Instance Method Details
#broadcast(channel_id, event_name, json) ⇒ Object
43 44 45 |
# File 'lib/binnacle/client.rb', line 43 def broadcast(channel_id, event_name, json) signal(channel_id, event_name, "", "", 'CABLE', nil, [], json, true) end |
#close ⇒ Object
76 77 78 |
# File 'lib/binnacle/client.rb', line 76 def close nil end |
#events(channel, date, start_hour, end_hour, lines) ⇒ Object
51 52 53 |
# File 'lib/binnacle/client.rb', line 51 def events(channel, date, start_hour, end_hour, lines) Binnacle::Event.events(connection, channel, date, start_hour, end_hour, lines) end |
#formatter ⇒ Object
Ruby Logger Implementation
65 66 67 |
# File 'lib/binnacle/client.rb', line 65 def formatter @formatter end |
#log_http_event(data) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/binnacle/client.rb', line 93 def log_http_event(data) session_id, client_id = session_and_client_ids event_name = %[#{data[:method]} #{data[:url]}] event = Binnacle::Event.new() event.configure(logging_channel_id, event_name, client_id, session_id, 'log', nil, data[:time], [], data) write(event) end |
#log_rails_event(data) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/binnacle/client.rb', line 84 def log_rails_event(data) session_id, client_id = session_and_client_ids event_name = %[#{data[:method]} #{data[:path]}] event = Binnacle::Event.new() event.configure(logging_channel_id, event_name, client_id, session_id, 'log', nil, data[:time], [], data) write(event) end |
#ready? ⇒ Boolean
80 81 82 |
# File 'lib/binnacle/client.rb', line 80 def ready? !connection.nil? end |
#recents(lines, since, channel) ⇒ Object
47 48 49 |
# File 'lib/binnacle/client.rb', line 47 def recents(lines, since, channel) Binnacle::Event.recents(connection, lines, since, channel) end |
#report_exception(exception, env, asynch = true) ⇒ Object
55 56 57 58 59 |
# File 'lib/binnacle/client.rb', line 55 def report_exception(exception, env, asynch = true) event = Binnacle::Trap::ExceptionEvent.new(exception, env) event.connection = connection asynch ? event.post_asynch : event.post end |
#session_and_client_ids ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/binnacle/client.rb', line 102 def session_and_client_ids if defined?(ActiveSupport::TaggedLogging) && Thread.current[:activesupport_tagged_logging_tags] session_id, client_id = Thread.current[:activesupport_tagged_logging_tags].first(2) else session_id, client_id = self.session_id, self.client_id end unless client_id # set it to the first non-loopback IP in the list client_id = Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address end [ session_id, client_id ] end |
#signal(channel_id, event_name, client_id, session_id, log_level, environment = Event.rails_env, tags = [], json = {}, asynch = false) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/binnacle/client.rb', line 32 def signal(channel_id, event_name, client_id, session_id, log_level, environment = Event.rails_env, = [], json = {}, asynch = false) event = Binnacle::Event.new() event.configure(channel_id, event_name, client_id, session_id, log_level, environment, nil, , json) event.connection = connection asynch ? event.post_asynch : event.post end |
#signal_asynch(channel_id, event_name, client_id = '', session_id = '', log_level = 'INFO', environment = Event.rails_env, tags = [], json = {}) ⇒ Object
39 40 41 |
# File 'lib/binnacle/client.rb', line 39 def signal_asynch(channel_id, event_name, client_id = '', session_id = '', log_level = 'INFO', environment = Event.rails_env, = [], json = {}) signal(channel_id, event_name, client_id, session_id, log_level, environment, , json, true) end |
#write(event) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/binnacle/client.rb', line 69 def write(event) if event event.connection = connection Binnacle.configuration.asynch_logging ? event.post_asynch : event.post end end |