syslogger5424 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/syslogger/formatter/rfc5424.rb +4 -4
- data/lib/syslogger/logger.rb +16 -0
- data/spec/syslogger/formatter/rfc5424_spec.rb +37 -2
- data/spec/syslogger_spec.rb +20 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5497cc4321c203d2828c59d18d79ed8e35d6ec69
|
4
|
+
data.tar.gz: 2610975569418bbed14c8d2dfe61e525fef5a936
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66105d5582b22820a619208cf844a9c97ca3156000b374aa77626f15fc1a848657cab6b6f3edb759e76f02f2ccfac8c0c3be7c7ab7f9411e66d93b5c82d06dce
|
7
|
+
data.tar.gz: a78949220b3e2e422ff6b5fc10dff8568a296e50a16c312bbf2700898b04901ddc5fc004cd8c3f6987862b4f134b9fd8a8960bda76ff0ba82e015c2efd6a0daa
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module SysLogger
|
2
2
|
module Formatter
|
3
3
|
class RFC5424 < ::Logger::Formatter
|
4
|
-
attr_reader :msgid
|
4
|
+
attr_reader :msgid
|
5
|
+
attr_accessor :procid, :appname
|
5
6
|
|
6
7
|
Format = "<%s>1 %s %s %s %s %s %s %s\n"
|
7
8
|
|
@@ -53,8 +54,7 @@ module SysLogger
|
|
53
54
|
@hostname = Socket.gethostname
|
54
55
|
@msgid = format_field(msgid, 32)
|
55
56
|
@procid = procid
|
56
|
-
@
|
57
|
-
@appname = format_field(appname, 48)
|
57
|
+
@appname = appname
|
58
58
|
|
59
59
|
self.facility = facility || :local7
|
60
60
|
end
|
@@ -88,7 +88,7 @@ module SysLogger
|
|
88
88
|
structured_data["meta"]["x-counter"] = @counter
|
89
89
|
sd = format_sdata(structured_data)
|
90
90
|
Format % [pri, datetime.strftime("%FT%T.%6N%:z"), @hostname,
|
91
|
-
@appname, format_field(@procid || Process.pid.to_s, 128),
|
91
|
+
format_field(@appname, 48), format_field(@procid || Process.pid.to_s, 128),
|
92
92
|
message_id, sd, line]
|
93
93
|
end
|
94
94
|
if lines.size == 1
|
data/lib/syslogger/logger.rb
CHANGED
@@ -16,6 +16,22 @@ module SysLogger
|
|
16
16
|
@default_formatter = SysLogger::Formatter::RFC5424.new
|
17
17
|
end
|
18
18
|
|
19
|
+
def appname=(appname)
|
20
|
+
@default_formatter.appname = appname
|
21
|
+
end
|
22
|
+
|
23
|
+
def appname
|
24
|
+
@default_formatter.appname
|
25
|
+
end
|
26
|
+
|
27
|
+
def procid=(procid)
|
28
|
+
@default_formatter.procid = procid
|
29
|
+
end
|
30
|
+
|
31
|
+
def procid
|
32
|
+
@default_formatter.appname
|
33
|
+
end
|
34
|
+
|
19
35
|
def <<(msg)
|
20
36
|
# Logger's version of this just dumps the input without formatting. there
|
21
37
|
# is never a case where we don't want to format the content to the syslog
|
@@ -3,10 +3,17 @@ require 'date'
|
|
3
3
|
|
4
4
|
describe SysLogger::Formatter::RFC5424 do
|
5
5
|
its(:msgid) { is_expected.to eq "-" }
|
6
|
-
its(:procid) { is_expected.to eq
|
7
|
-
its(:appname) { is_expected.to eq
|
6
|
+
its(:procid) { is_expected.to eq nil }
|
7
|
+
its(:appname) { is_expected.to eq nil }
|
8
8
|
its(:facility) { is_expected.to eq 23 }
|
9
9
|
|
10
|
+
let(:test_date) { DateTime.new(2019, 10, 31, 20, 8) }
|
11
|
+
let(:test_hostname) { "host1sf" }
|
12
|
+
|
13
|
+
before do
|
14
|
+
allow(Socket).to receive(:gethostname).and_return(test_hostname)
|
15
|
+
end
|
16
|
+
|
10
17
|
describe "#call" do
|
11
18
|
it "generates Format" do
|
12
19
|
expect(subject.call(::Logger::INFO, DateTime.now, "Prog", "Message")).
|
@@ -28,5 +35,33 @@ describe SysLogger::Formatter::RFC5424 do
|
|
28
35
|
end
|
29
36
|
expect(counter2).to be > counter1
|
30
37
|
end
|
38
|
+
|
39
|
+
context "nil appname" do
|
40
|
+
it "formats correctly" do
|
41
|
+
expect(Socket).to receive(:gethostname).and_return(test_hostname)
|
42
|
+
expect(subject).to receive(:gen_xgroup).and_return(74901736)
|
43
|
+
expect(subject.call(::Logger::INFO, test_date, "Prog", "Message")).to eq (
|
44
|
+
"<190>1 2019-10-31T20:08:00.000000+00:00 host1sf - #{Process.pid.to_s} Prog [meta x-group=\"74901736\" x-counter=\"1\"] Message\n"
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "custom appname" do
|
50
|
+
it "formats correctly" do
|
51
|
+
subject.appname = "short-appname"
|
52
|
+
expect(subject).to receive(:gen_xgroup).and_return(74901736)
|
53
|
+
expect(subject.call(::Logger::INFO, test_date, "Prog", "Message")).to eq (
|
54
|
+
"<190>1 2019-10-31T20:08:00.000000+00:00 host1sf short-appname #{Process.pid.to_s} Prog [meta x-group=\"74901736\" x-counter=\"1\"] Message\n"
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "truncates to 48 bytes" do
|
59
|
+
subject.appname = "this-is-a-very-long-appname-with-many-parts-in-it-for-sure-yep"
|
60
|
+
expect(subject).to receive(:gen_xgroup).and_return(74901736)
|
61
|
+
expect(subject.call(::Logger::INFO, test_date, "Prog", "Message")).to eq (
|
62
|
+
"<190>1 2019-10-31T20:08:00.000000+00:00 host1sf this-is-a-very-long-appname-with-many-parts-in-it #{Process.pid.to_s} Prog [meta x-group=\"74901736\" x-counter=\"1\"] Message\n"
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
31
66
|
end
|
32
67
|
end
|
data/spec/syslogger_spec.rb
CHANGED
@@ -1,9 +1,28 @@
|
|
1
1
|
describe SysLogger do
|
2
|
-
let(:
|
2
|
+
let(:io) { StringIO.new }
|
3
|
+
let(:logger) { SysLogger.new(io) }
|
3
4
|
|
4
5
|
describe '#new' do
|
5
6
|
it 'creates a Logger' do
|
6
7
|
expect(logger).to be_a SysLogger::Logger
|
7
8
|
end
|
8
9
|
end
|
10
|
+
|
11
|
+
describe "#appname" do
|
12
|
+
it 'returns nil if appname is nil' do
|
13
|
+
expect(logger.appname).to be_nil
|
14
|
+
logger.info('test')
|
15
|
+
expect(io.string).to match(
|
16
|
+
/<190>1.* #{Socket.gethostname} - #{Process.pid} - \[meta.*/
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'overrides the appname' do
|
21
|
+
logger.appname = 'an-appname'
|
22
|
+
logger.info('test')
|
23
|
+
expect(io.string).to match(
|
24
|
+
/<190>1.* #{Socket.gethostname} an-appname #{Process.pid} - \[meta.*/
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
9
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syslogger5424
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- EasyPost
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mono_logger
|