rumbrl 0.5.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rumbrl.rb +3 -0
- data/lib/rumbrl/formatter.rb +2 -11
- data/lib/rumbrl/kv.rb +2 -0
- data/lib/rumbrl/kv/formatter.rb +26 -0
- data/lib/rumbrl/kv/logger.rb +14 -0
- data/lib/rumbrl/logger.rb +11 -0
- data/lib/rumbrl/sumologic.rb +2 -0
- data/lib/rumbrl/sumologic/formatter.rb +34 -0
- data/lib/rumbrl/sumologic/logger.rb +14 -0
- data/lib/rumbrl/version.rb +1 -1
- data/spec/rumbrl/formatter_spec.rb +1 -5
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc82af5529740703aec6e83ed9b4464b81b2fb9f
|
4
|
+
data.tar.gz: f34cac33f367edb3a0831ab58d95cef6d83a05e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f85a35b5aabadcfeef69b3a354e4c4a24f59cfcfe68ae5f891c9f7c6fae6ca91d63ee0af9f1bdb1dfe4574f221b22d48551ef06fc429f10f41b264d82435d2d1
|
7
|
+
data.tar.gz: 8f7bca73de095dd2fe4203410d5150ae20ee0929a4b0371b387303807249044c9fdd5137e5b922ae1c3fe0186e9e7adeba2b12d91b4052972144ab5a3d7c7f5c
|
data/Gemfile.lock
CHANGED
data/lib/rumbrl.rb
CHANGED
data/lib/rumbrl/formatter.rb
CHANGED
@@ -4,10 +4,10 @@ require 'rumbrl/smash'
|
|
4
4
|
module Rumbrl
|
5
5
|
# Log4r formatter
|
6
6
|
class Formatter < ::Logger::Formatter
|
7
|
-
def call(
|
7
|
+
def call(_severity, _timestamp, _prog, msg)
|
8
8
|
return '' if omit_empty? && empty?(msg)
|
9
9
|
|
10
|
-
"
|
10
|
+
"#{format_msg(msg)}\n"
|
11
11
|
end
|
12
12
|
|
13
13
|
def omit_empty(switch)
|
@@ -32,14 +32,5 @@ module Rumbrl
|
|
32
32
|
def empty?(obj)
|
33
33
|
obj.respond_to?(:empty?) && obj.empty?
|
34
34
|
end
|
35
|
-
|
36
|
-
def app_namespace
|
37
|
-
ENV.fetch('LOG_APP_NAME', 'RubyApplication')
|
38
|
-
end
|
39
|
-
|
40
|
-
def appname(progname)
|
41
|
-
progname = (progname.nil? || progname.strip.empty?) ? '' : progname.strip
|
42
|
-
(progname.empty?) ? app_namespace : "#{app_namespace}::#{progname}"
|
43
|
-
end
|
44
35
|
end
|
45
36
|
end
|
data/lib/rumbrl/kv.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rumbrl/formatter'
|
2
|
+
require 'rumbrl/smash'
|
3
|
+
|
4
|
+
module Rumbrl
|
5
|
+
# Rumbrl KV module
|
6
|
+
module KV
|
7
|
+
# Log4r formatter that turns hashable objects into KV log entries
|
8
|
+
class Formatter < ::Rumbrl::Formatter
|
9
|
+
def format_msg(msg)
|
10
|
+
return "MESSAGE='#{super}'" unless msg.is_a?(Hash)
|
11
|
+
|
12
|
+
format_data ::Rumbrl::Smash.flatten(msg)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def format_data(data)
|
18
|
+
entry = ''
|
19
|
+
data.each do |k, v|
|
20
|
+
entry += " #{k.to_s.upcase}='#{v.to_s.gsub("'", '"')}'"
|
21
|
+
end
|
22
|
+
entry.strip
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rumbrl/kv/formatter'
|
2
|
+
|
3
|
+
module Rumbrl
|
4
|
+
# Rumbrl Sumologic module
|
5
|
+
module Sumologic
|
6
|
+
# Log4r formatter that turns hashable objects into KV log entries
|
7
|
+
# with some decorations specifically for sumologic
|
8
|
+
class Formatter < ::Rumbrl::KV::Formatter
|
9
|
+
def call(severity, timestamp, prg, msg)
|
10
|
+
return super if empty?(msg)
|
11
|
+
|
12
|
+
format_entry appname(prg), severity, timestamp, format_msg(msg)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def format_entry(app, sev, time, msg)
|
18
|
+
format(
|
19
|
+
"APP_NAME='%s' SEVERITY='%s' TIMESTAMP='%s' %s\n",
|
20
|
+
app, sev, time, msg
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def app_namespace
|
25
|
+
ENV.fetch('LOG_APP_NAME', 'RubyApplication')
|
26
|
+
end
|
27
|
+
|
28
|
+
def appname(prog)
|
29
|
+
prog = (prog.nil? || prog.strip.empty?) ? '' : prog.strip
|
30
|
+
(prog.empty?) ? app_namespace : "#{app_namespace}::#{prog}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Rumbrl
|
4
|
+
# Rumbrl Sumologic module
|
5
|
+
module Sumologic
|
6
|
+
# Log4r logger that uses the KV formatter
|
7
|
+
class Logger < ::Logger
|
8
|
+
def initialize(*args)
|
9
|
+
super
|
10
|
+
@formatter = ::Rumbrl::Sumologic::Formatter.new
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/rumbrl/version.rb
CHANGED
@@ -3,10 +3,6 @@ require_relative '../spec_helper'
|
|
3
3
|
describe Rumbrl::Formatter do
|
4
4
|
let(:formatter) { Rumbrl::Formatter.new }
|
5
5
|
|
6
|
-
before :each do
|
7
|
-
allow(ENV).to receive(:fetch).and_return 'SPECDEFAULT'
|
8
|
-
end
|
9
|
-
|
10
6
|
describe '#omit_empty?' do
|
11
7
|
it 'defaults to true' do
|
12
8
|
expect(formatter.omit_empty?).to be true
|
@@ -47,7 +43,7 @@ describe Rumbrl::Formatter do
|
|
47
43
|
|
48
44
|
context 'and msg is a string' do
|
49
45
|
it 'it returns a formatted string' do
|
50
|
-
expected = "
|
46
|
+
expected = "stuff\n"
|
51
47
|
res = formatter.call('INFO', nil, 'SPECS', 'stuff')
|
52
48
|
|
53
49
|
expect(res).to eq expected
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rumbrl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chr0n1x
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -100,8 +100,15 @@ files:
|
|
100
100
|
- lib/rumbrl/formatter.rb
|
101
101
|
- lib/rumbrl/grumble.rb
|
102
102
|
- lib/rumbrl/grumble_factory.rb
|
103
|
+
- lib/rumbrl/kv.rb
|
104
|
+
- lib/rumbrl/kv/formatter.rb
|
105
|
+
- lib/rumbrl/kv/logger.rb
|
103
106
|
- lib/rumbrl/log.rb
|
107
|
+
- lib/rumbrl/logger.rb
|
104
108
|
- lib/rumbrl/smash.rb
|
109
|
+
- lib/rumbrl/sumologic.rb
|
110
|
+
- lib/rumbrl/sumologic/formatter.rb
|
111
|
+
- lib/rumbrl/sumologic/logger.rb
|
105
112
|
- lib/rumbrl/version.rb
|
106
113
|
- rumbrl.gemspec
|
107
114
|
- spec/rumbrl/factory_spec.rb
|