Class: BrmLogger::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/logger/event.rb,
lib/brm-ruby-logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application, *args) ⇒ Logger

Returns a new instance of Logger.



21
22
23
24
25
26
27
28
# File 'lib/brm-ruby-logger.rb', line 21

def initialize(application,  *args)
 @application = application
 
 bunny_options = args.extract_options!
 @connection = Bunny.new bunny_options
 @connection.start
 @queue = @connection.queue "reactor.#{application}"
end

Instance Attribute Details

#applicationObject

Returns the value of attribute application.



14
15
16
# File 'lib/brm-ruby-logger.rb', line 14

def application
  @application
end

#connectionObject

Returns the value of attribute connection.



14
15
16
# File 'lib/brm-ruby-logger.rb', line 14

def connection
  @connection
end

#facet_idObject

Returns the value of attribute facet_id.



14
15
16
# File 'lib/brm-ruby-logger.rb', line 14

def facet_id
  @facet_id
end

#user_idObject

Returns the value of attribute user_id.



14
15
16
# File 'lib/brm-ruby-logger.rb', line 14

def user_id
  @user_id
end

Instance Method Details

#action(type, context = nil, event_ref = "") ⇒ Object



14
15
16
# File 'lib/logger/event.rb', line 14

def action(type, context=nil, event_ref="")
  event "Action", { "type" => type }, context, event_ref
end

#connect(type, action, with_id, with_type, attributes = nil, context = nil, event_ref = "") ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/logger/event.rb', line 65

def connect(type, action, with_id, with_type, attributes=nil, context=nil, event_ref="")
  data = {
    "action" => action,
    "type" => type,
    "withAgent" => { "id" => with_id, "type" => with_type }
  }
  data["attributes"] = attributes if attributes;
  event("Connect", data, context, event_ref)
end

#create(resource_id, resource_type, resource_attributes = nil, context = nil, event_ref = "") ⇒ Object



43
44
45
# File 'lib/logger/event.rb', line 43

def create(resource_id, resource_type, resource_attributes=nil, context=nil, event_ref="")
  resource_event("create", resource_id, resource_type, resource_attributes || {}, context, event_ref)
end

#delete(resource_id, resource_type, context = nil, event_ref = "") ⇒ Object



51
52
53
# File 'lib/logger/event.rb', line 51

def delete(resource_id, resource_type, context=nil, event_ref="")
  resource_event("delete", resource_id, resource_type, {}, context, event_ref)
end

#describe(type, resource, context = nil, event_ref = "") ⇒ Object



89
90
91
# File 'lib/logger/event.rb', line 89

def describe(type, resource, context=nil, event_ref="")
  event("Describe", { "type" => type, "resource" => resource }, context, event_ref)
end

#disconnectObject



30
31
32
# File 'lib/brm-ruby-logger.rb', line 30

def disconnect()
  @connection.stop
end

#event(event_name, data = nil, context = nil, event_ref = "") ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/brm-ruby-logger.rb', line 34

def event(event_name, data=nil, context=nil, event_ref="")
  event = HashWithIndifferentAccess.new
  event["data"] = data || {}
  event["context"] ||= {}
  
  
  event["data"]["agent"] = {:id => facet_id, :type => "facet"} if facet_id

  if user_id
    event["data"]["agent"] ||= {:id => user_id, :type => "user"}
    event["context"]["userID"] = user_id
  end
  event["metaData"] = {
    "timestamp" => Time.now.to_i * 1000,
    "eventName"  => event_name,
    "application" => application,
    "loggerVersion" => VERSION,
    "loggerType" => "ruby",
    "sequenceNumber" => sequence_number
  }

  event["metaData"]["eventRef"] = event_ref

  send event
end

#location(location_id = nil, location_type = "url", referrer_id = nil, referrer_type = "url", context = nil, event_ref = "") ⇒ Object



37
38
39
40
41
# File 'lib/logger/event.rb', line 37

def location(location_id=nil, location_type="url", referrer_id=nil, referrer_type="url", context=nil, event_ref="")
  data = { "location" => { "type" => location_type, "id" => location_id } }
  data["referrer"] = { "id" => referrer_id, "type" => referrer_type } if referrer_id
  event("Location", data, context, event_ref)
end

#message(type, recipients, msg, context = nil, event_ref = "") ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/logger/event.rb', line 4

def message type, recipients, msg, context=nil, event_ref=nil
  data = {
    "message" => msg,
    "recipients" => recipients,
    "type" => type
  }
  event "Message", data, context, event_ref
end

#register_event(service, step_name, step_num = 0, step_status = "success", complete = true, context = nil, event_ref = "") ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/logger/event.rb', line 124

def register_event(service, step_name, step_num=0, step_status="success", complete=true, context=nil, event_ref="")
  data = {
    "service" => service,
    "step" => {
      "num" => step_num,
      "name" => step_name,
      "status" => step_status
    },
    "complete" => complete
  }
  event("Register", data, context, event_ref)
end

#resource_event(type, resource_id, resource_type, attributes = nil, context = nil, event_ref = "") ⇒ Object



118
119
120
121
122
# File 'lib/logger/event.rb', line 118

def resource_event(type, resource_id, resource_type, attributes=nil, context=nil, event_ref="")
  resource = attributes || {}
  resource.update("id" => resource_id, "type" => resource_type)
  event "Resource", { "resource" => resource, "type" => type }, context, event_ref
end

#sequence_numberObject



16
17
18
19
# File 'lib/brm-ruby-logger.rb', line 16

def sequence_number
  @sequence_number ||= 0
  @sequence_number += 1
end

#session_event(type, service_name, agent_id, agent_type, context, event_ref) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/logger/event.rb', line 102

def session_event(type, service_name, agent_id, agent_type, context, event_ref)
  if type != "start"
    user_id = nil
    facet_id = nil
  elsif agent_id
    if agent_type == "facet"
      facet_id = agent_id
    else
      user_id = agent_id
    end
  end

  event("Session", { "type" => type, "service" => service_name }, context, event_ref)
end

#session_expired(service_name, agent_id = nil, agent_type = nil, context = nil, event_ref = "") ⇒ Object



33
34
35
# File 'lib/logger/event.rb', line 33

def session_expired(service_name, agent_id=nil, agent_type=nil, context=nil, event_ref="")
  session_event("expired", service_name, agent_id, agent_type, context, event_ref)
end

#share(destination, resource_id, resource_type, context = nil, event_ref = "") ⇒ Object



55
56
57
58
# File 'lib/logger/event.rb', line 55

def share(destination, resource_id, resource_type, context=nil, event_ref="")
  resource = {"id" => resource_id, "type" => resource_type }
  event("Share", {"resource" => resource, "destination" => destination }, context, event_ref)
end

#sign_in(service_name, agent_id = nil, agent_type = nil, context = nil, event_ref = "") ⇒ Object



19
20
21
# File 'lib/logger/event.rb', line 19

def (service_name, agent_id=nil, agent_type=nil, context=nil, event_ref="")
  session_event("start", service_name, agent_id, agent_type, context, event_ref)
end

#sign_in_failed(service_name, agent_id = nil, agent_type = nil, context = nil, event_ref = "") ⇒ Object



28
29
30
# File 'lib/logger/event.rb', line 28

def (service_name, agent_id=nil, agent_type=nil, context=nil, event_ref="")
  session_event("failed", service_name, agent_id, agent_type, context, event_ref)
end

#sign_out(service_name, agent_id = nil, agent_type = nil, context = nil, event_ref = "") ⇒ Object



24
25
26
# File 'lib/logger/event.rb', line 24

def sign_out(service_name, agent_id=nil, agent_type=nil, context=nil, event_ref="")
  session_event("end", service_name, agent_id, agent_type, context, event_ref)
end

#sign_up(service, step_status = "success", context = nil, event_ref = "") ⇒ Object



94
95
96
# File 'lib/logger/event.rb', line 94

def (service, step_status="success", context=nil, event_ref="")
  register_event(service, "register", 1, step_status, true, context, event_ref)
end

#system(type, msg = "", context = nil, event_ref = "") ⇒ Object



85
86
87
# File 'lib/logger/event.rb', line 85

def system(type, msg="", context=nil, event_ref="")
  event("System", { "type" => type, "message" => msg }, context, event_ref)
end

#transaction(type, resources, from_id, from_type, context = nil, event_ref = "") ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/logger/event.rb', line 75

def transaction(type, resources, from_id, from_type, context=nil, event_ref="")
  data = {
    "type" => type,
    "resources" => resources,
    "fromAgent" => { "id" => from_id, "type" => from_type }
  }
  event("Transaction", data, context, event_ref)
end

#unsubscribe(service, context = nil, event_ref = "") ⇒ Object



98
99
100
# File 'lib/logger/event.rb', line 98

def unsubscribe(service, context=nil, event_ref="")
  register_event(service, "unsubscribe", -1, "success", true, context, event_ref)
end

#update(resource_id, resource_type, resource_attributes = nil, context = nil, event_ref = "") ⇒ Object



47
48
49
# File 'lib/logger/event.rb', line 47

def update(resource_id, resource_type, resource_attributes=nil, context=nil, event_ref="")
  resource_event("update", resource_id, resource_type, resource_attributes || {}, context, event_ref)
end