class Binnacle::Client
Attributes
api_key[RW]
api_secret[RW]
client_id[RW]
connection[RW]
logging_channel_id[RW]
ready[W]
session_id[RW]
Public Class Methods
new(api_key = nil, api_secret = nil, endpoint = nil, logging_channel_id = nil)
click to toggle source
# 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
Public Instance Methods
broadcast(channel_id, event_name, json)
click to toggle source
# 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()
click to toggle source
# File lib/binnacle/client.rb, line 76 def close nil end
events(channel, date, start_hour, end_hour, lines)
click to toggle source
# 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()
click to toggle source
Ruby Logger Implementation
# File lib/binnacle/client.rb, line 65 def formatter @formatter end
log_http_event(data)
click to toggle source
# 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)
click to toggle source
# 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?()
click to toggle source
# File lib/binnacle/client.rb, line 80 def ready? !connection.nil? end
recents(lines, since, channel)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# File lib/binnacle/client.rb, line 32 def signal(channel_id, event_name, client_id, session_id, log_level, environment = Event.rails_env, tags = [], json = {}, asynch = false) event = Binnacle::Event.new() event.configure(channel_id, event_name, client_id, session_id, log_level, environment, nil, tags, 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 = {})
click to toggle source
# 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, tags = [], json = {}) signal(channel_id, event_name, client_id, session_id, log_level, environment, tags, json, true) end
write(event)
click to toggle source
# 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