rf_logger 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -10
- data/lib/rf_logger.rb +4 -4
- data/lib/rf_logger/active_record.rb +1 -0
- data/lib/rf_logger/rails.rb +4 -1
- data/lib/rf_logger/rails/rails_compatibility.rb +4 -3
- data/lib/rf_logger/rory.rb +9 -2
- data/lib/rf_logger/rory/initialize_request_middleware.rb +0 -4
- data/lib/rf_logger/sequel.rb +2 -1
- data/lib/rf_logger/version.rb +1 -1
- data/spec/lib/rf_logger/log_for_notification_spec.rb +2 -0
- data/spec/lib/rf_logger/rails/rails_compatibility_spec.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b595e7d05f3277b9c9835fa966c9c3a4a1e6fec9
|
4
|
+
data.tar.gz: aecb196b1dbd862dffab3ec5dc341ab68ec1e31b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b16adcfce60a563371920d59b2bfc05b701c5c74a0572bdaace67bf747914b95ae6128142f8f51eb4e3530c6d3768af99223d65877c7e563ad0fed2e7bd6d22
|
7
|
+
data.tar.gz: 96c307c32bb8880a67b3a159713d6734f990bd63a3ac2e1ea6c76235177ecac1a2b8add190331cb8e90eb0d70710c5bf615de914edab98bd05f0f130e662bc39
|
data/README.md
CHANGED
@@ -16,16 +16,16 @@ The API provides helper methods for each severity (i.e. `Logger.debug`). In add
|
|
16
16
|
|
17
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
18
|
|
19
|
-
##Integration
|
19
|
+
## Integration
|
20
20
|
Integrating RfLogger into your project requires the following steps:
|
21
21
|
* Include the rf_logger code in your project
|
22
22
|
* Create a migration
|
23
23
|
* Add a model
|
24
24
|
|
25
|
-
#### Including rf_logger
|
26
|
-
|
25
|
+
#### Including rf_logger
|
26
|
+
Place the following in your Gemfile:
|
27
27
|
|
28
|
-
```gem 'rf_logger',
|
28
|
+
```gem 'rf_logger', "0.3"```
|
29
29
|
|
30
30
|
Also make sure you include rf_logger and the logger you're going to be using:
|
31
31
|
|
@@ -42,7 +42,16 @@ Alters Rails.logger to append `request_id=89f25715-3e5d-4d85-9352-843a1aeec7d0`
|
|
42
42
|
|
43
43
|
#### Rory Requirements
|
44
44
|
|
45
|
-
Support Rory => `0.
|
45
|
+
Support Rory => `0.8`
|
46
|
+
|
47
|
+
|
48
|
+
#### Debug Framework detection and loading plug-ins
|
49
|
+
|
50
|
+
Will puts to STDOUT frameworks detected and any errors.
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
ENV["RF_LOGGER_LOAD_DEBUG"] = "true"
|
54
|
+
```
|
46
55
|
|
47
56
|
#### RfLogger::RequestHeaders
|
48
57
|
|
@@ -69,7 +78,7 @@ RfLogger::RequestHeaders.new(accepts: "application/json").to_hash
|
|
69
78
|
|
70
79
|
#### Migration
|
71
80
|
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
|
81
|
+
###### Sequel
|
73
82
|
```
|
74
83
|
create_table :logs do
|
75
84
|
primary_key :id
|
@@ -99,20 +108,20 @@ end
|
|
99
108
|
#### Model
|
100
109
|
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
110
|
|
102
|
-
######Sequel
|
111
|
+
###### Sequel
|
103
112
|
```
|
104
113
|
class Log < RfLogger::Sequel::Logger
|
105
114
|
end
|
106
115
|
```
|
107
116
|
|
108
|
-
######ActiveRecord
|
117
|
+
###### ActiveRecord
|
109
118
|
```
|
110
119
|
class Log < RfLogger::ActiveRecord::Logger
|
111
120
|
end
|
112
121
|
```
|
113
122
|
|
114
123
|
|
115
|
-
##Configuration
|
124
|
+
## Configuration
|
116
125
|
Configuration mostly sets up additional notifications beyond the actual logging.
|
117
126
|
|
118
127
|
```ruby
|
@@ -131,7 +140,7 @@ end
|
|
131
140
|
|
132
141
|
As you see above, you can specify different notifications for different levels or environments when you log an event.
|
133
142
|
|
134
|
-
##Notification
|
143
|
+
## Notification
|
135
144
|
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.
|
136
145
|
|
137
146
|
Example:
|
data/lib/rf_logger.rb
CHANGED
@@ -4,10 +4,10 @@ module RfLogger
|
|
4
4
|
def self.try_to_load(file)
|
5
5
|
begin
|
6
6
|
require file
|
7
|
-
yield
|
8
7
|
puts "RfLogger: Detected #{file}." if ENV["RF_LOGGER_LOAD_DEBUG"]
|
9
|
-
|
10
|
-
|
8
|
+
yield
|
9
|
+
rescue LoadError => e
|
10
|
+
puts "RfLogger: #{file} not detected.\n\t#{e.to_s}" if ENV["RF_LOGGER_LOAD_DEBUG"]
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -15,4 +15,4 @@ end
|
|
15
15
|
RfLogger.try_to_load("rails") { require "rf_logger/rails" }
|
16
16
|
RfLogger.try_to_load("active_record") { require "rf_logger/active_record" }
|
17
17
|
RfLogger.try_to_load("rory") { require "rf_logger/rory" }
|
18
|
-
RfLogger.try_to_load("sequel") { require
|
18
|
+
RfLogger.try_to_load("sequel") { puts "RfLogger: require 'rf_logger/sequel'; before inheriting from RfLogger::Sequel::Logger" if ENV["RF_LOGGER_LOAD_DEBUG"] }
|
data/lib/rf_logger/rails.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require "rf_logger/rails/rails_compatibility"
|
2
2
|
require "rails/version"
|
3
|
-
RfLogger
|
3
|
+
puts "RfLogger: Rails version #{Rails::VERSION::STRING}" if ENV["RF_LOGGER_LOAD_DEBUG"]
|
4
|
+
RfLogger::RailsCompatibility.new.call {
|
5
|
+
require "rf_logger/rails/key_value_tagged_logging"
|
6
|
+
}
|
4
7
|
require "rf_logger/request/request_headers"
|
5
8
|
require "rf_logger/rails/initialize_request_middleware"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module RfLogger
|
2
2
|
class RailsCompatibility
|
3
|
-
MAX
|
4
|
-
MIN
|
3
|
+
MAX = "5.0.99"
|
4
|
+
MIN = "3.2"
|
5
5
|
Incompatible = Class.new(StandardError)
|
6
6
|
|
7
7
|
def initialize(rails_version: Gem::Version.new(::Rails::VERSION::STRING))
|
@@ -21,7 +21,8 @@ module RfLogger
|
|
21
21
|
attr_reader :rails_version
|
22
22
|
|
23
23
|
def rails_not_support_message
|
24
|
-
|
24
|
+
return unless ENV["RF_LOGGER_LOAD_DEBUG"] = "true"
|
25
|
+
puts "RfLogger: These patches change Rails private methods and are only known to work for Rails #{MIN} through #{MAX}. Current version #{rails_version}"
|
25
26
|
end
|
26
27
|
|
27
28
|
def rails_supported?
|
data/lib/rf_logger/rory.rb
CHANGED
@@ -1,2 +1,9 @@
|
|
1
|
-
require "
|
2
|
-
|
1
|
+
require "rory/version"
|
2
|
+
|
3
|
+
if Gem::Version.new(Rory::VERSION) >= Gem::Version.new("0.8")
|
4
|
+
puts "RfLogger: Rory version #{Rory::VERSION}" if ENV["RF_LOGGER_LOAD_DEBUG"]
|
5
|
+
require "rf_logger/rory/initialize_request_middleware"
|
6
|
+
require "rf_logger/request/request_headers"
|
7
|
+
else
|
8
|
+
puts "RfLogger: requires Rory 0.8 or greater. Version #{Rory::VERSION} is not support." if ENV["RF_LOGGER_LOAD_DEBUG"]
|
9
|
+
end
|
@@ -1,9 +1,5 @@
|
|
1
1
|
require "rf_logger/request/request_middleware"
|
2
|
-
require "rory/version"
|
3
2
|
|
4
|
-
unless Gem::Version.new(Rory::VERSION) >= Gem::Version.new("0.8")
|
5
|
-
raise "RfLogger require Rory 0.8 or greater. Version #{Rory::VERSION} is not support."
|
6
|
-
end
|
7
3
|
Rory::Application.initializers.insert_after "rory.request_middleware", "rf_logger.request_middleware" do |app|
|
8
4
|
app.middleware.insert_after Rory::RequestId, RfLogger::RequestMiddleware
|
9
5
|
end
|
data/lib/rf_logger/sequel.rb
CHANGED
data/lib/rf_logger/version.rb
CHANGED
@@ -7,12 +7,12 @@ RSpec.describe RfLogger::RailsCompatibility do
|
|
7
7
|
|
8
8
|
context "far left" do
|
9
9
|
let(:rails_version) { 2.9 }
|
10
|
-
it { expect { subject.call }.
|
10
|
+
it { expect { |b| subject.call(&b) }.to_not yield_control }
|
11
11
|
end
|
12
12
|
|
13
13
|
context "edge left" do
|
14
14
|
let(:rails_version) { 3.1 }
|
15
|
-
it { expect { subject.call }.
|
15
|
+
it { expect { |b| subject.call(&b) }.to_not yield_control }
|
16
16
|
end
|
17
17
|
|
18
18
|
context "middle edge left" do
|
@@ -32,11 +32,11 @@ RSpec.describe RfLogger::RailsCompatibility do
|
|
32
32
|
|
33
33
|
context "edge right" do
|
34
34
|
let(:rails_version) { 5.1 }
|
35
|
-
it { expect { subject.call }.
|
35
|
+
it { expect { |b| subject.call(&b) }.to_not yield_control }
|
36
36
|
end
|
37
37
|
|
38
38
|
context "far right" do
|
39
39
|
let(:rails_version) {6.0}
|
40
|
-
it { expect { subject.call }.
|
40
|
+
it { expect { |b| subject.call(&b) }.to_not yield_control }
|
41
41
|
end
|
42
42
|
end
|