rf_logger 0.0.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +5 -13
  2. data/.rspec +1 -1
  3. data/.travis.yml +3 -0
  4. data/README.md +99 -2
  5. data/lib/rf_logger/active_record/logger.rb +35 -0
  6. data/lib/rf_logger/active_record.rb +1 -0
  7. data/lib/rf_logger/configuration.rb +1 -1
  8. data/lib/rf_logger/notifications/error_notification_environment_constraints.rb +2 -1
  9. data/lib/rf_logger/rails/initialize_request_middleware.rb +9 -0
  10. data/lib/rf_logger/rails/key_value_tagged_logging.rb +58 -0
  11. data/lib/rf_logger/rails/rails_compatibility.rb +33 -0
  12. data/lib/rf_logger/rails.rb +5 -0
  13. data/lib/rf_logger/request/request_headers.rb +34 -0
  14. data/lib/rf_logger/request/request_middleware.rb +30 -0
  15. data/lib/rf_logger/request/request_tags.rb +9 -0
  16. data/lib/rf_logger/rory/initialize_request_middleware.rb +7 -0
  17. data/lib/rf_logger/rory.rb +2 -0
  18. data/lib/rf_logger/sequel/base.rb +46 -0
  19. data/lib/rf_logger/sequel/logger.rb +53 -0
  20. data/lib/rf_logger/sequel.rb +2 -0
  21. data/lib/rf_logger/version.rb +1 -1
  22. data/lib/rf_logger.rb +13 -42
  23. data/rf_logger.gemspec +5 -5
  24. data/spec/lib/rf_logger/active_record/logger_spec.rb +49 -0
  25. data/spec/lib/rf_logger/configuration_spec.rb +19 -14
  26. data/spec/lib/rf_logger/log_for_notification_spec.rb +3 -3
  27. data/spec/lib/rf_logger/notifications/error_notification_environment_constraints_spec.rb +26 -12
  28. data/spec/lib/rf_logger/notifications/error_notification_spec.rb +9 -9
  29. data/spec/lib/rf_logger/rails/rails_compatibility_spec.rb +42 -0
  30. data/spec/lib/rf_logger/request/request_headers_spec.rb +83 -0
  31. data/spec/lib/rf_logger/request/request_middleware_spec.rb +35 -0
  32. data/spec/lib/rf_logger/{sequel_logger_spec.rb → sequel/logger_spec.rb} +46 -16
  33. data/spec/lib/rf_logger/simple_logger_spec.rb +8 -8
  34. data/spec/lib/rf_logger_spec.rb +8 -6
  35. data/spec/spec_helper.rb +2 -1
  36. data/spec/support/request_id_shared_examples.rb +21 -0
  37. metadata +63 -37
  38. data/lib/rf_logger/sequel_logger.rb +0 -41
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MjNhYTQ2MGY4ZGU0MTVhOGU2ODdhM2IwMmU1MGVmMWNlZWM5MGYyYg==
5
- data.tar.gz: !binary |-
6
- ZTNhNDcxZmQ0MWUxODE1MjdlYTFmZGFlMzhkOTI1MmEzYjI3ZTk5MA==
2
+ SHA1:
3
+ metadata.gz: 2e5e11c14fc59ec80d79f806e6499f3d24204a21
4
+ data.tar.gz: 6b5b1ebd0c6f083d64c11ed070ec3d7ca9024a24
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- M2Y1ZjNmODBmM2JkY2EzODU4NGE4ZTcyZWZhOTVlOGUxN2MwNTQ5OGE0OTli
10
- OWNiN2RiZWJlZGQzNzFjNjkzOWMwZDg1NjhjODAwYTNmOWFmNDk5MGY3NTEw
11
- OTYxZDI2YTA4YWNmNjQ5NWMyMzFiNGE3OWY5YWIyOGU3MjNmYzg=
12
- data.tar.gz: !binary |-
13
- MzUxZGJkYTdkMjQzMTkxZWU5NDFmZmYyZmVkOTI3ZWM3NWJiODZjMzM0N2I2
14
- YWViNzgzMGQ0MzFiMTA1OTNkMDE2ZWM5ZDJhOGEzMGUyNGQyZjdhZWRiMmU2
15
- YzVkOGViNWNhNjkyMmRmYWNlNDIxNjUyZTU2N2FhMDk3MDA0YTQ=
6
+ metadata.gz: 92ee70365528780fa73a8a48b2abc608e938c23f48b2bce20ce026bc501c12195ffa7decb8d5f1772071131c9d5e5a1523d2d749bee2e1263c29d22f98aebf88
7
+ data.tar.gz: 5ad0b5c67ba647eb012f2789596eedc0be6b8ad724814ac45d4b4f7d1783565cf20f3ab36076cb553f813b1202b9d7ead4d9a9fb2a5ac1968996e6c1c61091e2
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
1
  --color
2
- --format=nested
2
+ --format=documentation
3
3
  --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.7
data/README.md CHANGED
@@ -12,8 +12,105 @@ The API provides helper methods for each severity (i.e. `Logger.debug`). In add
12
12
  - target_type (We use this in cases where we want to tie a log record to a particular entity or object in the database, for example User)
13
13
  - target_id (This is used in conjunction with target_type, as the unique identifier for the relevant entity)
14
14
  - metadata (Additional information such as error details and backtraces or other messages, stored as a hash)
15
+ * Include in this Hash is the rf_logger_request_tags, which by default contains the request_id if available.
16
+
17
+ This gem includes RfLogger::SimpleLogger, RfLogger::Sequel::Logger and RfLogger::ActiveRecord::Logger loggers as options that adhere to this API. The fields above should be passed into helper methods as a hash.
18
+
19
+ ##Integration##
20
+ Integrating RfLogger into your project requires the following steps:
21
+ * Include the rf_logger code in your project
22
+ * Create a migration
23
+ * Add a model
24
+
25
+ #### Including rf_logger ####
26
+ Currently, RfLogger is included from the Github repo. Place the following in your Gemfile:
27
+
28
+ ```gem 'rf_logger', :github => 'renewablefunding/rf_logger' , :tag => "0.3.0"```
29
+
30
+ Also make sure you include rf_logger and the logger you're going to be using:
31
+
32
+
33
+ #### Rails
34
+
35
+ ##### Requirements
36
+
37
+ Support Rails `3.2` to `~> 5.0`
38
+
39
+ ##### Features
40
+
41
+ Alters Rails.logger to append `request_id=89f25715-3e5d-4d85-9352-843a1aeec7d0`
42
+
43
+ #### Rory Requirements
44
+
45
+ Support Rory => `0.7`
46
+
47
+ #### RfLogger::RequestHeaders
48
+
49
+ *If in the context of a request*
50
+ ```ruby
51
+ RfLogger::RequestHeaders.new(type: nil).to_hash
52
+ #=> {"X-Request-Id" => "89f25715-3e5d-4d85-9352-843a1aeec7d0"}
53
+
54
+ ```
55
+
56
+ *It defaults to content type of JSON*
57
+ ```ruby
58
+ RfLogger::RequestHeaders.new.to_hash
59
+ #=> {"Content-Type" => "application/json"}
60
+
61
+ ```
62
+
63
+ *Any additional headers can be added*
64
+ ```ruby
65
+ RfLogger::RequestHeaders.new(accepts: "application/json").to_hash
66
+ #=> {"Content-Type" => "application/json", "Accepts" => "application/json"}
67
+
68
+ ```
69
+
70
+ #### Migration
71
+ Assuming your logger will persist to a database, you'll need to create a table. While the api should make it pretty easy to determine which fields you'll need, here are the guts of what you'd need for both the SequelLogger and RailsLogger:
72
+ ######Sequel
73
+ ```
74
+ create_table :logs do
75
+ primary_key :id
76
+ column :actor, :text, :null => false
77
+ column :action, :text, :null => false
78
+ column :target_type, :text
79
+ column :target_id, :text
80
+ column :metadata, :text
81
+ column :created_at, 'timestamp with time zone', :null => false
82
+ Integer :level, :null => false, :default => 0
83
+ end
84
+ ```
85
+
86
+ ###### ActiveRecord
87
+ ```
88
+ create_table :logs do |table|
89
+ table.integer :level, null: false, default: 0
90
+ table.string :actor
91
+ table.string :action
92
+ table.string :target_type
93
+ table.string :target_id
94
+ table.string :metadata
95
+ table.timestamps null: false
96
+ end
97
+ ```
98
+
99
+ #### Model
100
+ Again, assuming you'll be using the SequelLogger or RailsLogger (or some other logger that persists to a datasource), you'll want to create a Model that wraps your logger. This is as simple as creating a class that inherits from your logger (though you can make it more complex as your project needs dictate):
101
+
102
+ ######Sequel
103
+ ```
104
+ class Log < RfLogger::Sequel::Logger
105
+ end
106
+ ```
107
+
108
+ ######ActiveRecord
109
+ ```
110
+ class Log < RfLogger::ActiveRecord::Logger
111
+ end
112
+ ```
15
113
 
16
- This gem includes RfLogger::SimpleLogger and RfLogger::Sequel logger as two options that adhere to this API. The fields above should be passed into helper methods as a hash.
17
114
 
18
115
  ##Configuration##
19
116
  Configuration mostly sets up additional notifications beyond the actual logging.
@@ -32,7 +129,7 @@ RfLogger.configure do |c|
32
129
  end
33
130
  ```
34
131
 
35
- As you seen above, you can specify different notifications for different levels or environments whend you log an event.
132
+ As you see above, you can specify different notifications for different levels or environments when you log an event.
36
133
 
37
134
  ##Notification##
38
135
  While you have to implement notifiers yourself, the API is fairly simple. The class must respond to .send_notification. The argument passed in is an object that includes a #subject (which can be defined in the configuration (see above), and #details, which is the metadata in YAML format. Future versions of this may allow for other transformations of the log data.
@@ -0,0 +1,35 @@
1
+ require 'active_record'
2
+ require "rf_logger/request/request_tags"
3
+ require "rf_logger/levels"
4
+
5
+ module RfLogger
6
+ module ActiveRecord
7
+ class Logger < ::ActiveRecord::Base
8
+ self.table_name = "logs"
9
+ extend RfLogger::RequestTags
10
+ class << self
11
+
12
+ RfLogger::LEVELS.each do |level|
13
+ define_method level.to_sym do |entry|
14
+ add level, entry
15
+ end
16
+ end
17
+
18
+ def add(level, entry)
19
+ attributes = {
20
+ :level => RfLogger::LEVELS.index(level.to_sym),
21
+ :action => entry[:action],
22
+ :actor => entry[:actor],
23
+ :metadata => entry[:metadata] || {},
24
+ :target_type => entry[:target_type],
25
+ :target_id => entry[:target_id],
26
+ }
27
+ attributes[:metadata].merge!(request_tags: rf_logger_request_tags) unless rf_logger_request_tags.nil?
28
+ create(attributes)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ RfLogger::RailsLogger = RfLogger::ActiveRecord::Logger
@@ -0,0 +1 @@
1
+ require "rf_logger/active_record/logger"
@@ -61,7 +61,7 @@ module RfLogger
61
61
 
62
62
  def framework_environment
63
63
  case
64
- when defined?(Rails) then Rails.env
64
+ when defined?(::Rails) then ::Rails.env
65
65
  when defined?(Rory) then ENV['RORY_STAGE']
66
66
  when defined?(Padrino) then Padrino.environment
67
67
  when defined?(Sinatra::Application) then Sinatra::Application.environment
@@ -17,7 +17,8 @@ module RfLogger
17
17
 
18
18
  def excluded?
19
19
  except = @constraints[:except]
20
- except && except.include?(@environment)
20
+ return false if except.nil?
21
+ except.include?(@environment)
21
22
  end
22
23
  end
23
24
  end
@@ -0,0 +1,9 @@
1
+ require "rf_logger/request/request_middleware"
2
+
3
+ module RfLogger
4
+ class InitializeRequestMiddleware < Rails::Railtie
5
+ initializer "rf_logging.initialize_request_middleware" do |app|
6
+ app.middleware.insert_after ::ActionDispatch::RequestId, RequestMiddleware
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,58 @@
1
+ require "rails/rack/logger"
2
+
3
+ module Rails
4
+ module Rack
5
+ module TagsAsKeyValue
6
+ def initialize(app, taggers={})
7
+ super
8
+ @taggers = taggers.values
9
+ @taggers_keys = taggers.keys
10
+ end
11
+
12
+ protected def compute_tags(*args)
13
+ super(*args).collect.with_index do |value, index|
14
+ "#{@taggers_keys[index]}=#{value}"
15
+ end
16
+ end
17
+ end
18
+
19
+ Logger.prepend(TagsAsKeyValue)
20
+ end
21
+ end
22
+
23
+ require "active_support/tagged_logging"
24
+
25
+ module ActiveSupport
26
+ module RfTagsText
27
+ def tags_text
28
+ tags = current_tags
29
+ if tags.any?
30
+ tags.collect { |tag| "#{tag} " }.join
31
+ end
32
+ end
33
+ end
34
+
35
+ if defined? TaggedLogging::Formatter # Rails 4 or greater
36
+ TaggedLogging::Formatter.prepend(RfTagsText)
37
+ else
38
+ TaggedLogging.prepend(RfTagsText) # Rails 3.2
39
+ end
40
+ end
41
+
42
+ require "action_dispatch/middleware/request_id"
43
+
44
+ module ActionDispatch
45
+ class RequestId
46
+ private def internal_request_id
47
+ [Rails.application.class.parent_name.underscore, SecureRandom.uuid].join("-")
48
+ end
49
+ end
50
+ end
51
+
52
+ require "rails/engine/railties"
53
+
54
+ class KeyValueKeyLogging < ::Rails::Railtie
55
+ initializer "rf_logging.add_log_tag_request_id" do |app|
56
+ app.config.log_tags = { request_id: :uuid }
57
+ end
58
+ end
@@ -0,0 +1,33 @@
1
+ module RfLogger
2
+ class RailsCompatibility
3
+ MAX = "5.0.99"
4
+ MIN = "3.2"
5
+ Incompatible = Class.new(StandardError)
6
+
7
+ def initialize(rails_version: Gem::Version.new(::Rails::VERSION::STRING))
8
+ @rails_version = rails_version
9
+ end
10
+
11
+ def call
12
+ if rails_supported?
13
+ yield
14
+ else
15
+ rails_not_support_message
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :rails_version
22
+
23
+ def rails_not_support_message
24
+ raise Incompatible, "These patches change Rails private methods and are only known to work for Rails #{MIN} through #{MAX}"
25
+ end
26
+
27
+ def rails_supported?
28
+ rails_version >= Gem::Version.new(MIN) && rails_version <= Gem::Version.new(MAX)
29
+ end
30
+ end
31
+ end
32
+
33
+
@@ -0,0 +1,5 @@
1
+ require "rf_logger/rails/rails_compatibility"
2
+ require "rails/version"
3
+ RfLogger::RailsCompatibility.new.call { require "rf_logger/rails/key_value_tagged_logging" }
4
+ require "rf_logger/request/request_headers"
5
+ require "rf_logger/rails/initialize_request_middleware"
@@ -0,0 +1,34 @@
1
+ module RfLogger
2
+ class RequestHeaders
3
+ attr_reader :api_token, :type, :request_id, :content_type, :other
4
+
5
+ def initialize(type: "application/json",
6
+ api_token: nil,
7
+ request_id: self.class.request_id,
8
+ other: {},
9
+ **other_key_headers)
10
+ @type = type
11
+ @api_token = api_token
12
+ @request_id = request_id
13
+ @content_type = type
14
+ @other = other
15
+ @other_key_headers = other_key_headers
16
+ end
17
+
18
+ def self.request_id
19
+ (Thread.current.get_inheritable_attribute(:rf_logger_request_tags)||{})[:request_id]
20
+ end
21
+
22
+ def to_hash
23
+ {
24
+ "Content-Type" => content_type,
25
+ "Api-Token" => api_token,
26
+ "X-Request-Id" => request_id
27
+ }.merge(other_key_headers).merge(other).reject { |_, v| v.nil? }
28
+ end
29
+
30
+ def other_key_headers
31
+ @other_key_headers.each_with_object({}) { |(k, v), h| h[k.to_s.split("_").map(&:capitalize).join("-")] = v }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,30 @@
1
+ require "thread/inheritable_attributes"
2
+
3
+ module RfLogger
4
+ class RequestMiddleware
5
+ # @param [Hash] options
6
+ # @option opts [Hash{:label => "header_name"}] :tagged The subject
7
+ def initialize(app, options={})
8
+ @app = app
9
+ @tagged = options.fetch(:tagged, { request_id: "X-Request-Id" })
10
+ end
11
+
12
+ def call(env)
13
+ @env = env
14
+ set_tagged_thread_var
15
+ @app.call(@env)
16
+ end
17
+
18
+ def tagged
19
+ @tagged.each_with_object({}) do |(key, value), hash|
20
+ hash[key] = @env[value]
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def set_tagged_thread_var
27
+ Thread.current.set_inheritable_attribute(:rf_logger_request_tags, tagged)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ require "thread/inheritable_attributes"
2
+
3
+ module RfLogger
4
+ module RequestTags
5
+ def rf_logger_request_tags
6
+ Thread.current.get_inheritable_attribute(:rf_logger_request_tags)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require "rf_logger/request/request_middleware"
2
+ unless Gem::Version.new(Rory::VERSION) >= Gem::Version.new("0.8")
3
+ raise "RfLogger require Rory 0.8 or greater. Version #{Rory::VERSION} is not support."
4
+ end
5
+ Rory::Application.initializers.insert_after "rory.request_middleware", "rf_logger.request_middleware" do |app|
6
+ app.middleware.insert_after Rory::RequestId, RfLogger::RequestMiddleware
7
+ end
@@ -0,0 +1,2 @@
1
+ require "rf_logger/rory/initialize_request_middleware"
2
+ require "rf_logger/request/request_headers"
@@ -0,0 +1,46 @@
1
+ require 'forwardable'
2
+ require 'rf_logger/version'
3
+ require 'rf_logger/configuration'
4
+ require 'rf_logger/levels'
5
+
6
+ require 'rf_logger/notifications/error_notification'
7
+ require 'rf_logger/notifications/error_notification_environment_constraints'
8
+
9
+ require 'rf_logger/simple_logger'
10
+ require 'rf_logger/log_for_notification'
11
+
12
+
13
+ module RfLogger
14
+ class UndefinedSetting < StandardError; end
15
+
16
+ class << self
17
+ extend Forwardable
18
+
19
+ Configuration.defined_settings.each do |setting|
20
+ def_delegators :configuration, setting, "#{setting.to_s}="
21
+ end
22
+
23
+ def configuration
24
+ @configuration ||= RfLogger::Configuration.new
25
+ end
26
+
27
+ def configure(&block)
28
+ unless block
29
+ raise ArgumentError.new("You tried to .configure without a block!")
30
+ end
31
+ yield configuration
32
+ end
33
+
34
+ def clear_configuration!
35
+ @configuration = nil
36
+ end
37
+
38
+ def configure!(&block)
39
+ unless block
40
+ raise ArgumentError.new('You tried to .configure without a block!')
41
+ end
42
+ clear_configuration!
43
+ yield configuration
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,53 @@
1
+ require "json"
2
+ require "rf_logger/sequel/base"
3
+ require "rf_logger/request/request_tags"
4
+
5
+ module RfLogger
6
+ module Sequel
7
+ class Logger < ::Sequel::Model(::Sequel::Model.db.fetch('select 1'))
8
+ extend RfLogger::RequestTags
9
+
10
+ class << self
11
+ def inherited(subclass)
12
+ super
13
+ subclass.set_dataset underscore(demodulize(subclass.name.pluralize)).to_sym
14
+ end
15
+
16
+ RfLogger::LEVELS.each do |level|
17
+ define_method level.to_sym do |entry|
18
+ log = add level, entry
19
+
20
+ notification_log = LogForNotification.new(entry.merge(:level => level))
21
+ ErrorNotification.dispatch_error(notification_log)
22
+ log
23
+ end
24
+ end
25
+
26
+ def add(level, entry)
27
+ entry[:level] = RfLogger::LEVELS.index(level.to_sym)
28
+ entry[:actor] = entry[:actor] || ''
29
+ entry[:metadata] = entry[:metadata] || {}
30
+ entry[:metadata].merge!(request_tags: rf_logger_request_tags) unless rf_logger_request_tags.nil?
31
+ entry[:created_at] = Time.now
32
+ create(entry)
33
+ end
34
+ end
35
+
36
+ def metadata
37
+ return nil if self[:metadata].nil?
38
+ JSON.parse(self[:metadata])
39
+ end
40
+
41
+ def metadata=(metadata_hash)
42
+ metadata_as_json = metadata_hash.nil? ? nil : metadata_hash.to_json
43
+ self[:metadata] = metadata_as_json
44
+ end
45
+
46
+ def display_level
47
+ RfLogger::LEVELS[level]
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ RfLogger::SequelLogger = RfLogger::Sequel::Logger
@@ -0,0 +1,2 @@
1
+ require "rf_logger/sequel/base"
2
+ require "rf_logger/sequel/model"
@@ -1,3 +1,3 @@
1
1
  module RfLogger
2
- VERSION = "0.0.4"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/rf_logger.rb CHANGED
@@ -1,47 +1,18 @@
1
- require 'forwardable'
2
- require 'yaml'
3
- require 'rf_logger/version'
4
- require 'rf_logger/configuration'
5
- require 'rf_logger/levels'
6
-
7
- require 'rf_logger/notifications/error_notification'
8
- require 'rf_logger/notifications/error_notification_environment_constraints'
9
-
10
- require 'rf_logger/simple_logger'
11
- require 'rf_logger/log_for_notification'
12
-
1
+ require "rf_logger/version"
13
2
 
14
3
  module RfLogger
15
- class UndefinedSetting < StandardError; end
16
-
17
- class << self
18
- extend Forwardable
19
-
20
- Configuration.defined_settings.each do |setting|
21
- def_delegators :configuration, setting, "#{setting.to_s}="
22
- end
23
-
24
- def configuration
25
- @configuration ||= RfLogger::Configuration.new
26
- end
27
-
28
- def configure(&block)
29
- unless block
30
- raise ArgumentError.new("You tried to .configure without a block!")
31
- end
32
- yield configuration
33
- end
34
-
35
- def clear_configuration!
36
- @configuration = nil
37
- end
38
-
39
- def configure!(&block)
40
- unless block
41
- raise ArgumentError.new('You tried to .configure without a block!')
42
- end
43
- clear_configuration!
44
- yield configuration
4
+ def self.try_to_load(file)
5
+ begin
6
+ require file
7
+ yield
8
+ puts "RfLogger: Detected #{file}." if ENV["RF_LOGGER_LOAD_DEBUG"]
9
+ rescue LoadError
10
+ puts "RfLogger: #{file} not detected." if ENV["RF_LOGGER_LOAD_DEBUG"]
45
11
  end
46
12
  end
47
13
  end
14
+
15
+ RfLogger.try_to_load("rails") { require "rf_logger/rails" }
16
+ RfLogger.try_to_load("active_record") { require "rf_logger/active_record" }
17
+ RfLogger.try_to_load("rory") { require "rf_logger/rory" }
18
+ RfLogger.try_to_load("sequel") { require "rf_logger/sequel" }
data/rf_logger.gemspec CHANGED
@@ -5,11 +5,11 @@ require 'rf_logger/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'rf_logger'
8
- s.version = '0.0.4'
8
+ s.version = RfLogger::VERSION
9
9
  s.date = '2014-02-20'
10
10
  s.summary = "A logger that adheres to Renewable Funding logging conventions"
11
11
  s.description = "A logger that allows specification of severity, applicable entity/records, metadata, and optional notifications"
12
- s.authors = ["Dave Miller", "Laurie Kemmerer", "Maher Hawash", "Ravi Gadad"]
12
+ s.authors = ["Dustin Zeisler", "Dave Miller", "Laurie Kemmerer", "Maher Hawash", "Ravi Gadad"]
13
13
  s.email = 'devteam@renewfund.com'
14
14
  s.homepage = ''
15
15
  s.license = 'MIT'
@@ -19,11 +19,11 @@ Gem::Specification.new do |s|
19
19
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
20
  s.require_paths = ["lib"]
21
21
 
22
+ s.add_runtime_dependency "thread-inheritable_attributes", "~> 0.1"
22
23
  s.add_development_dependency "bundler", "~> 1.3"
23
24
  s.add_development_dependency "rake"
24
- s.add_development_dependency 'rspec'
25
- s.add_development_dependency 'watchr'
26
- s.add_development_dependency 'debugger'
25
+ s.add_development_dependency 'rspec', "~> 3.4"
27
26
  s.add_development_dependency 'simplecov'
28
27
  s.add_development_dependency 'sequel'
28
+ s.add_development_dependency 'activerecord'
29
29
  end
@@ -0,0 +1,49 @@
1
+ require "rf_logger/active_record/logger"
2
+ require "active_record"
3
+
4
+ describe RfLogger::ActiveRecord::Logger do
5
+ include_examples "RfLogger::RequestId", subject: described_class
6
+
7
+ it "keeps backwards compatibility" do
8
+ expect(described_class).to eq RfLogger::RailsLogger
9
+ end
10
+
11
+ RfLogger::LEVELS.each do |level|
12
+ before do
13
+ allow(described_class).to receive(:create)
14
+ allow(described_class).to receive(:table_name)
15
+ end
16
+
17
+ describe ".#{level}" do
18
+ context "when rf_logger_request_tags is empty" do
19
+ it "creates new Log object with level = #{level}" do
20
+ allow(described_class).to receive(:rf_logger_request_tags){nil}
21
+ described_class.send(level.to_sym, action: 'log me')
22
+ expect(described_class).to have_received(:create).with(
23
+ :level => RfLogger::LEVELS.index(level.to_sym),
24
+ :action => 'log me',
25
+ :actor => nil,
26
+ :metadata => {},
27
+ :target_type => nil,
28
+ :target_id => nil,
29
+ )
30
+ end
31
+ end
32
+
33
+ context "when rf_logger_request_tags is not empty" do
34
+ it "creates new Log object with level = #{level}" do
35
+ allow(described_class).to receive(:rf_logger_request_tags){{test: "hello"}}
36
+ described_class.send(level.to_sym, action: 'log me')
37
+ expect(described_class).to have_received(:create).with(
38
+ :level => RfLogger::LEVELS.index(level.to_sym),
39
+ :action => 'log me',
40
+ :actor => nil,
41
+ :metadata => {:request_tags => {test: "hello"}},
42
+ :target_type => nil,
43
+ :target_id => nil,
44
+ )
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end