brm-ruby-logger 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/brm-ruby-logger.rb +69 -0
- data/lib/logger/event.rb +142 -0
- data/spec/brm-ruby-logger_spec.rb +54 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +99 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 mathieuravaux
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= brm-ruby-logger
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 mathieuravaux. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "brm-ruby-logger"
|
8
|
+
gem.summary = "Ruby event logger for the BRM real-time analytics and BI solution"
|
9
|
+
gem.description = ""
|
10
|
+
gem.email = "mathieu.ravaux@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/mathieuravaux/brm-ruby-logger"
|
12
|
+
gem.authors = ["mathieuravaux"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_dependency "bunny"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "brm-ruby-logger #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,69 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bunny"
|
5
|
+
require "active_support"
|
6
|
+
require "pp"
|
7
|
+
|
8
|
+
require "logger/event.rb"
|
9
|
+
|
10
|
+
module BrmLogger
|
11
|
+
VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).chomp
|
12
|
+
|
13
|
+
class Logger
|
14
|
+
attr_accessor :connection, :user_id, :facet_id, :application
|
15
|
+
|
16
|
+
def sequence_number
|
17
|
+
@sequence_number ||= 0
|
18
|
+
@sequence_number += 1
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(user_id, application, *args)
|
22
|
+
@user_id = user_id
|
23
|
+
@application = application
|
24
|
+
|
25
|
+
bunny_options = args.extract_options!
|
26
|
+
@connection = Bunny.new bunny_options
|
27
|
+
@connection.start
|
28
|
+
end
|
29
|
+
|
30
|
+
def disconnect()
|
31
|
+
@connection.stop
|
32
|
+
end
|
33
|
+
|
34
|
+
def event(eventName, data=nil, context=nil, event_ref="")
|
35
|
+
event = HashWithIndifferentAccess.new
|
36
|
+
event["data"] = data || {}
|
37
|
+
event["context"] = context || {}
|
38
|
+
|
39
|
+
|
40
|
+
event["data"]["agent"] = {:id => facet_id, :type => "facet"} if facet_id
|
41
|
+
|
42
|
+
if user_id
|
43
|
+
event["data"]["agent"] ||= {:id => user_id, :type => "user"}
|
44
|
+
event["context"]["userID"] = user_id
|
45
|
+
end
|
46
|
+
|
47
|
+
event["metaData"] = {
|
48
|
+
"timestamp" => Time.now.to_i * 1000,
|
49
|
+
"eventName" => $eventName,
|
50
|
+
"application" => application,
|
51
|
+
"loggerVersion" => VERSION,
|
52
|
+
"loggerType" => "ruby",
|
53
|
+
"sequenceNumber" => sequence_number
|
54
|
+
}
|
55
|
+
|
56
|
+
event["metaData"]["eventRef"] = event_ref
|
57
|
+
|
58
|
+
send event
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
private
|
64
|
+
def send event
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
data/lib/logger/event.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
module BrmLogger
|
2
|
+
class Logger
|
3
|
+
|
4
|
+
def message type, recipients, msg, context=nil, event_ref=nil
|
5
|
+
data = {
|
6
|
+
"message" => msg,
|
7
|
+
"recipients" => recipients,
|
8
|
+
"type" => type
|
9
|
+
}
|
10
|
+
event "Message", data, context, event_ref
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def action(type, context=nil, event_ref="")
|
15
|
+
event "Action", { "type" => type }, context, event_ref
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def sign_in(service_name, agent_id=nil, agent_type=nil, context=nil, event_ref="")
|
20
|
+
session_event("start", service_name, agent_id, agent_type, context, event_ref)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def sign_out(service_name, agent_id=nil, agent_type=nil, context=nil, event_ref="")
|
25
|
+
session_event("end", service_name, agent_id, agent_type, context, event_ref)
|
26
|
+
end
|
27
|
+
|
28
|
+
def sign_in_failed(service_name, agent_id=nil, agent_type=nil, context=nil, event_ref="")
|
29
|
+
session_event("failed", service_name, agent_id, agent_type, context, event_ref)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def session_expired(service_name, agent_id=nil, agent_type=nil, context=nil, event_ref="")
|
34
|
+
session_event("expired", service_name, agent_id, agent_type, context, event_ref)
|
35
|
+
end
|
36
|
+
|
37
|
+
def location(location_id=nil, location_type="url", referrer_id=nil, referrer_type="url", context=nil, event_ref="")
|
38
|
+
data = { "location" => { "type" => location_type, "id" => location_id } }
|
39
|
+
data["referrer"] = { "id" => referrer_id, "type" => referrer_type } if referrer_id
|
40
|
+
event("Location", data, context, event_ref)
|
41
|
+
end
|
42
|
+
|
43
|
+
def create(resource_id, resource_type, resource_attributes=nil, context=nil, event_ref="")
|
44
|
+
resource_event("create", resource_id, resource_type, resource_attributes || {}, context, event_ref)
|
45
|
+
end
|
46
|
+
|
47
|
+
def update(resource_id, resource_type, resource_attributes=nil, context=nil, event_ref="")
|
48
|
+
resource_event("update", resource_id, resource_type, resource_attributes || {}, context, event_ref)
|
49
|
+
end
|
50
|
+
|
51
|
+
def delete(resource_id, resource_type, context=nil, event_ref="")
|
52
|
+
resource_event("delete", resource_id, resource_type, {}, context, event_ref)
|
53
|
+
end
|
54
|
+
|
55
|
+
def share(destination, resource_id, resource_type, context=nil, event_ref="")
|
56
|
+
resource = {"id" => resource_id, "type" => resource_type }
|
57
|
+
event("Share", {"resource" => resource, "destination" => destination }, context, event_ref)
|
58
|
+
end
|
59
|
+
|
60
|
+
def message(type, recipients, msg, context=nil, event_ref="")
|
61
|
+
data = { "message" => msg, "recipients" => recipients, "type" => type }
|
62
|
+
event("Message", data, context, event_ref)
|
63
|
+
end
|
64
|
+
|
65
|
+
def connect(type, action, with_id, with_type, attributes=nil, context=nil, event_ref="")
|
66
|
+
data = {
|
67
|
+
"action" => action,
|
68
|
+
"type" => type,
|
69
|
+
"withAgent" => { "id" => with_id, "type" => with_type }
|
70
|
+
}
|
71
|
+
data["attributes"] = attributes if attributes;
|
72
|
+
event("Connect", data, context, event_ref)
|
73
|
+
end
|
74
|
+
|
75
|
+
def transaction(type, resources, from_id, from_type, context=nil, event_ref="")
|
76
|
+
data = {
|
77
|
+
"type" => type,
|
78
|
+
"resources" => resources,
|
79
|
+
"fromAgent" => { "id" => from_id, "type" => from_type }
|
80
|
+
}
|
81
|
+
event("Transaction", data, context, event_ref)
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def system(type, msg="", context=nil, event_ref="")
|
86
|
+
event("System", { "type" => type, "message" => msg }, context, event_ref)
|
87
|
+
end
|
88
|
+
|
89
|
+
def describe(type, resource, context=nil, event_ref="")
|
90
|
+
event("Describe", { "type" => type, "resource" => resource }, context, event_ref)
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def sign_up(service, step_status="success", context=nil, event_ref="")
|
95
|
+
register_event(service, "register", 1, step_status, true, context, event_ref)
|
96
|
+
end
|
97
|
+
|
98
|
+
def unsubscribe(service, context=nil, event_ref="")
|
99
|
+
register_event(service, "unsubscribe", -1, "success", true, context, event_ref)
|
100
|
+
end
|
101
|
+
|
102
|
+
def session_event(type, service_name, agent_id, agent_type, context, event_ref)
|
103
|
+
if type != "start"
|
104
|
+
user_id = nil
|
105
|
+
facet_id = nil
|
106
|
+
elsif agent_id
|
107
|
+
if agent_type == "facet"
|
108
|
+
facet_id = agent_id
|
109
|
+
else
|
110
|
+
user_id = agent_id
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
event("Session", { "type" => type, "service" => service_name }, context, event_ref)
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
def resource_event(type, resource_id, resource_type, attributes=nil, context=nil, event_ref="")
|
119
|
+
resource = attributes || {}
|
120
|
+
resource.update("id" => resource_id, "type" => resource_type)
|
121
|
+
event "Resource", { "resource" => resource, "type" => type }, context, event_ref
|
122
|
+
end
|
123
|
+
|
124
|
+
def register_event(service, step_name, step_num=0, step_status="success", complete=true, context=nil, event_ref="")
|
125
|
+
data = {
|
126
|
+
"service" => service,
|
127
|
+
"step" => {
|
128
|
+
"num" => step_num,
|
129
|
+
"name" => step_name,
|
130
|
+
"status" => step_status
|
131
|
+
},
|
132
|
+
"complete" => complete
|
133
|
+
}
|
134
|
+
event("Register", data, context, event_ref)
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
RABBITMQ_HOST = 'mimesis12.typhon.net'
|
4
|
+
RABBITMQ_PORT = 5672
|
5
|
+
RABBITMQ_USERNAME = 'guest'
|
6
|
+
RABBITMQ_PASSWORD = 'guest'
|
7
|
+
RABBITMQ_VHOST = '/'
|
8
|
+
|
9
|
+
# RABBITMQ_VHOST = 'bmbubbler_test'
|
10
|
+
# RABBITMQ_USERNAME = 'blackmamba'
|
11
|
+
# RABBITMQ_PASSWORD = 'blackmamba'
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
describe "BrmLogger" do
|
16
|
+
before(:each) do
|
17
|
+
user_id = "123"
|
18
|
+
application = "brm-ruby-logger-tests"
|
19
|
+
@logger = BrmLogger::Logger.new(user_id, application,
|
20
|
+
# :logging => true,
|
21
|
+
:host => RABBITMQ_HOST,
|
22
|
+
:port => RABBITMQ_PORT,
|
23
|
+
:user => RABBITMQ_USERNAME,
|
24
|
+
:pass => RABBITMQ_PASSWORD,
|
25
|
+
:vhost => RABBITMQ_VHOST
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
after(:each) do
|
30
|
+
@logger.disconnect
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should connect to the QA RabbitMQ" do
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should send custom events" do
|
37
|
+
@logger.message("think", { "id" => "123", "type" => "facet" }, "Salut");
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should send generic Action events" do
|
41
|
+
# action (générique), dont envoi de post
|
42
|
+
@logger.action "Salut"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should send user sign-ins" do
|
46
|
+
@logger.facet_id = "JeanClaude"
|
47
|
+
@logger.sign_in "test_service"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should send user account creation events" do
|
51
|
+
@logger.describe "create", {"id" => "123", "type" => "User", "name" => "Bob" }
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brm-ruby-logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- mathieuravaux
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-08 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 9
|
31
|
+
version: 1.2.9
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: bunny
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
description: ""
|
47
|
+
email: mathieu.ravaux@gmail.com
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
53
|
+
- LICENSE
|
54
|
+
- README.rdoc
|
55
|
+
files:
|
56
|
+
- .document
|
57
|
+
- .gitignore
|
58
|
+
- LICENSE
|
59
|
+
- README.rdoc
|
60
|
+
- Rakefile
|
61
|
+
- VERSION
|
62
|
+
- lib/brm-ruby-logger.rb
|
63
|
+
- lib/logger/event.rb
|
64
|
+
- spec/brm-ruby-logger_spec.rb
|
65
|
+
- spec/spec.opts
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/mathieuravaux/brm-ruby-logger
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --charset=UTF-8
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.3.6
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Ruby event logger for the BRM real-time analytics and BI solution
|
97
|
+
test_files:
|
98
|
+
- spec/brm-ruby-logger_spec.rb
|
99
|
+
- spec/spec_helper.rb
|