logger_facade 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/Gemfile.lock +1 -1
- data/README.md +6 -5
- data/lib/logger_facade/plugins/logstash.rb +7 -7
- data/lib/logger_facade/version.rb +1 -1
- data/spec/integration/plugins/logstash_spec.rb +29 -0
- data/spec/spec_helper.rb +0 -8
- data/spec/unit/plugins/logstash_spec.rb +15 -15
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dc0e14861809751be33ef99cd453eaea0419812
|
4
|
+
data.tar.gz: 83fbb29db67b52a84ee4f91f046a9d3a24d099ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5631cd425804a69ec3415a1354068007bad120f9ea1825200f0bf8fef2c662d5ec5916e899c59a485c874dacb03d819d87dfbb077d941267e1497f5fd66e603
|
7
|
+
data.tar.gz: 37aaf0c880273988833194e43803c8caa006f73ce5083f3dd3842ce0e8e9fd14ddc927ef92f8420f0a55bbfb79749287cbbfa495a1f0742f6e67b3ba2d1256f6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -174,10 +174,8 @@ LoggerFacade::Manager.use(plugin)
|
|
174
174
|
### LoggerFacade::Plugins::Logstash
|
175
175
|
|
176
176
|
```ruby
|
177
|
-
#
|
178
|
-
config = { level: :debug }
|
179
|
-
|
180
|
-
# configuration is optional in Logstash plugin
|
177
|
+
# required paramaters config
|
178
|
+
config = { level: :debug, filename: '/tmp/log.logstash' }
|
181
179
|
plugin = LoggerFacade::Plugins::Logstash.new(config);
|
182
180
|
LoggerFacade::Manager.use(plugin)
|
183
181
|
|
@@ -185,7 +183,8 @@ LoggerFacade::Manager.use(plugin)
|
|
185
183
|
# by default logrotation is disabled and you should consider using a proper tool such logrotate.
|
186
184
|
# but you can use some Logger (from stdlib) options.
|
187
185
|
config = {
|
188
|
-
level: :debug
|
186
|
+
level: :debug,
|
187
|
+
filename: '/tmp/log.logstash',
|
189
188
|
device: {
|
190
189
|
shift_age: 'daily', # (optional) daily/weekly/monthly
|
191
190
|
shift_size: 1024000 # (optional) bytes
|
@@ -194,6 +193,8 @@ config = {
|
|
194
193
|
|
195
194
|
```
|
196
195
|
|
196
|
+
**NOTE:** When using with ruby daemons gem, use absolute path for file configuration.
|
197
|
+
|
197
198
|
## LoggerFacade::Plugins
|
198
199
|
|
199
200
|
If you wanna use a custom plugin you just need to use an object that responds to the following contract:
|
@@ -8,8 +8,12 @@ module LoggerFacade::Plugins
|
|
8
8
|
super("LoggerFacade::Plugins::Logstash", configuration)
|
9
9
|
|
10
10
|
fail "Invalid configuration filename: #{config.filename}" unless config.filename
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
11
14
|
|
12
|
-
|
15
|
+
def logdevice
|
16
|
+
@logdevice ||= if config["device"]
|
13
17
|
shift_age = config.device["shift_age"]
|
14
18
|
shift_size = config.device["shift_size"]
|
15
19
|
LogDeviceWithRotation.new(config.filename, shift_age, shift_size)
|
@@ -18,10 +22,6 @@ module LoggerFacade::Plugins
|
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
|
-
private
|
22
|
-
|
23
|
-
attr_reader :logdevice
|
24
|
-
|
25
25
|
def log(severity, message, logger, metadata)
|
26
26
|
return unless is_level_active(severity)
|
27
27
|
return unless logdevice
|
@@ -37,8 +37,8 @@ module LoggerFacade::Plugins
|
|
37
37
|
'@timestamp' => ts.iso8601,
|
38
38
|
'@fields' => metadata
|
39
39
|
}
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
logdevice.write("#{Yajl::Encoder.encode(json)}\n")
|
42
42
|
end
|
43
43
|
|
44
44
|
class LogDeviceWithRotation < ::Logger::LogDevice
|
@@ -0,0 +1,29 @@
|
|
1
|
+
describe LoggerFacade::Plugins::Logstash do
|
2
|
+
|
3
|
+
let(:filename) { "./spec/log.logstash" }
|
4
|
+
let(:time) { Time.new(1983, 01, 25, 13, 10, 01, '+00:00') }
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
FileUtils.rm(filename) rescue nil
|
8
|
+
allow(Time).to receive(:now) { time }
|
9
|
+
LoggerFacade::Manager.clear_plugins
|
10
|
+
config = { level: :debug, filename: filename }
|
11
|
+
plugin = LoggerFacade::Plugins::Logstash.new(config)
|
12
|
+
LoggerFacade::Manager.use(plugin)
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:each) do
|
16
|
+
FileUtils.rm(filename)
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:log) do
|
20
|
+
LoggerFacade::Manager.get_logger 'SPEC_LOGGER'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'logs to file' do
|
24
|
+
log.debug("message info", { context: true })
|
25
|
+
logline = "{\"@timestamp\":\"1983-01-25T13:10:01Z\",\"@fields\":{\"context\":true,\"pid\":#{Process.pid},\"severity\":\"debug\",\"logger\":\"SPEC_LOGGER\",\"message\":\"message info\"}}\n"
|
26
|
+
expect(File.read(filename)).to eq(logline)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,14 +16,6 @@ require 'logger_facade'
|
|
16
16
|
|
17
17
|
Dir['spec/support/**/*.rb'].each &method(:require)
|
18
18
|
|
19
|
-
RSpec.configure do |c|
|
20
|
-
c.around(:each) do |example|
|
21
|
-
Timeout::timeout(2) {
|
22
|
-
example.run
|
23
|
-
}
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
19
|
module TimeTestHelper
|
28
20
|
def with_mock_time(t = 0)
|
29
21
|
mc = class <<Time; self; end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
1
|
describe LoggerFacade::Plugins::Logstash do
|
4
2
|
include LevelTestHelper
|
5
3
|
|
@@ -21,7 +19,8 @@ describe LoggerFacade::Plugins::Logstash do
|
|
21
19
|
it 'defaults to logdevice without rotation' do
|
22
20
|
expect(LoggerFacade::Plugins::Logstash::LogDeviceWithoutRotation)
|
23
21
|
.to receive(:new).with(filename)
|
24
|
-
described_class.new(config)
|
22
|
+
subject = described_class.new(config)
|
23
|
+
subject.debug("logger", "message")
|
25
24
|
end
|
26
25
|
|
27
26
|
it 'uses ruby Logger config' do
|
@@ -30,7 +29,8 @@ describe LoggerFacade::Plugins::Logstash do
|
|
30
29
|
config[:device] = { shift_age: age, shift_size: size }
|
31
30
|
expect(LoggerFacade::Plugins::Logstash::LogDeviceWithRotation)
|
32
31
|
.to receive(:new).with(filename, age, size)
|
33
|
-
described_class.new(config)
|
32
|
+
subject = described_class.new(config)
|
33
|
+
subject.debug("logger", "message")
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'raises an error on invalid filename configuration' do
|
@@ -76,7 +76,7 @@ describe LoggerFacade::Plugins::Logstash do
|
|
76
76
|
it("writes a valid json") do
|
77
77
|
expect(file).to receive(:write) do |msg|
|
78
78
|
data = nil
|
79
|
-
expect { data =
|
79
|
+
expect { data = Yajl::Parser.new.parse(msg) }.not_to raise_exception
|
80
80
|
expect(data).to be
|
81
81
|
end
|
82
82
|
subject.send(severity, logger, message)
|
@@ -96,7 +96,7 @@ describe LoggerFacade::Plugins::Logstash do
|
|
96
96
|
|
97
97
|
it("writes logstash timestamp format") do
|
98
98
|
expect(file).to receive(:write) do |msg|
|
99
|
-
data =
|
99
|
+
data = Yajl::Parser.new.parse(msg)
|
100
100
|
expect(data["@timestamp"]).to eq(time.iso8601)
|
101
101
|
end
|
102
102
|
subject.send(severity, logger, message)
|
@@ -104,7 +104,7 @@ describe LoggerFacade::Plugins::Logstash do
|
|
104
104
|
|
105
105
|
it("uses metadata timestamp") do
|
106
106
|
expect(file).to receive(:write) do |msg|
|
107
|
-
data =
|
107
|
+
data = Yajl::Parser.new.parse(msg)
|
108
108
|
expect(data["@timestamp"]).to eq(ts.iso8601)
|
109
109
|
end
|
110
110
|
subject.send(severity, logger, message, metadata: metadata)
|
@@ -112,7 +112,7 @@ describe LoggerFacade::Plugins::Logstash do
|
|
112
112
|
|
113
113
|
it("doesn't write field timestamp") do
|
114
114
|
expect(file).to receive(:write) do |msg|
|
115
|
-
data =
|
115
|
+
data = Yajl::Parser.new.parse(msg)["@fields"]
|
116
116
|
expect(data["timestamp"]).to be_nil
|
117
117
|
end
|
118
118
|
subject.send(severity, logger, message, metadata: metadata)
|
@@ -121,7 +121,7 @@ describe LoggerFacade::Plugins::Logstash do
|
|
121
121
|
|
122
122
|
it("writes fields") do
|
123
123
|
expect(file).to receive(:write) do |msg|
|
124
|
-
data =
|
124
|
+
data = Yajl::Parser.new.parse(msg)
|
125
125
|
expect(data["@fields"]).to be
|
126
126
|
end
|
127
127
|
subject.send(severity, logger, message)
|
@@ -129,7 +129,7 @@ describe LoggerFacade::Plugins::Logstash do
|
|
129
129
|
|
130
130
|
it("writes severity") do
|
131
131
|
expect(file).to receive(:write) do |msg|
|
132
|
-
data =
|
132
|
+
data = Yajl::Parser.new.parse(msg)["@fields"]
|
133
133
|
expect(data["severity"]).to eq(severity.to_s)
|
134
134
|
end
|
135
135
|
subject.send(severity, logger, message)
|
@@ -137,7 +137,7 @@ describe LoggerFacade::Plugins::Logstash do
|
|
137
137
|
|
138
138
|
it("writes logger") do
|
139
139
|
expect(file).to receive(:write) do |msg|
|
140
|
-
data =
|
140
|
+
data = Yajl::Parser.new.parse(msg)["@fields"]
|
141
141
|
expect(data["logger"]).to eq(logger)
|
142
142
|
end
|
143
143
|
subject.send(severity, logger, message)
|
@@ -145,7 +145,7 @@ describe LoggerFacade::Plugins::Logstash do
|
|
145
145
|
|
146
146
|
it("writes message") do
|
147
147
|
expect(file).to receive(:write) do |msg|
|
148
|
-
data =
|
148
|
+
data = Yajl::Parser.new.parse(msg)["@fields"]
|
149
149
|
expect(data["message"]).to eq(message)
|
150
150
|
end
|
151
151
|
subject.send(severity, logger, message)
|
@@ -154,7 +154,7 @@ describe LoggerFacade::Plugins::Logstash do
|
|
154
154
|
it("writes other metadata fields") do
|
155
155
|
metadata = { context: true }
|
156
156
|
expect(file).to receive(:write) do |msg|
|
157
|
-
data =
|
157
|
+
data = Yajl::Parser.new.parse(msg)["@fields"]
|
158
158
|
expect(data["context"]).to eq(true)
|
159
159
|
end
|
160
160
|
subject.send(severity, logger, message, metadata: metadata)
|
@@ -165,7 +165,7 @@ describe LoggerFacade::Plugins::Logstash do
|
|
165
165
|
it('writes the exception message') do
|
166
166
|
error = Exception.new('test log')
|
167
167
|
expect(file).to receive(:write) do |msg|
|
168
|
-
data =
|
168
|
+
data = Yajl::Parser.new.parse(msg)["@fields"]
|
169
169
|
expect(data["message"]).to eq("test log")
|
170
170
|
end
|
171
171
|
subject.send(severity, logger, error)
|
@@ -175,7 +175,7 @@ describe LoggerFacade::Plugins::Logstash do
|
|
175
175
|
error = Exception.new('test log')
|
176
176
|
error.set_backtrace "stacktrace"
|
177
177
|
expect(file).to receive(:write) do |msg|
|
178
|
-
data =
|
178
|
+
data = Yajl::Parser.new.parse(msg)["@fields"]
|
179
179
|
expect(data["backtrace"]).to eq(error.backtrace)
|
180
180
|
end
|
181
181
|
subject.send(severity, logger, error)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logger_facade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Januário
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -208,6 +208,7 @@ files:
|
|
208
208
|
- lib/logger_facade/plugins/logstash.rb
|
209
209
|
- lib/logger_facade/version.rb
|
210
210
|
- logger_facade.gemspec
|
211
|
+
- spec/integration/plugins/logstash_spec.rb
|
211
212
|
- spec/spec_helper.rb
|
212
213
|
- spec/unit/log_spec.rb
|
213
214
|
- spec/unit/loggable_spec.rb
|
@@ -243,6 +244,7 @@ signing_key:
|
|
243
244
|
specification_version: 4
|
244
245
|
summary: Logger Facade library
|
245
246
|
test_files:
|
247
|
+
- spec/integration/plugins/logstash_spec.rb
|
246
248
|
- spec/spec_helper.rb
|
247
249
|
- spec/unit/log_spec.rb
|
248
250
|
- spec/unit/loggable_spec.rb
|