syslogger 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/syslogger.rb +5 -3
- data/spec/syslogger_spec.rb +29 -18
- metadata +3 -2
data/lib/syslogger.rb
CHANGED
@@ -4,9 +4,10 @@ require 'thread'
|
|
4
4
|
|
5
5
|
class Syslogger
|
6
6
|
|
7
|
-
VERSION = "1.
|
7
|
+
VERSION = "1.6.0"
|
8
8
|
|
9
|
-
attr_reader :level, :ident, :options, :facility, :max_octets
|
9
|
+
attr_reader :level, :ident, :options, :facility, :max_octets
|
10
|
+
attr_accessor :formatter
|
10
11
|
|
11
12
|
MAPPING = {
|
12
13
|
Logger::DEBUG => Syslog::LOG_DEBUG,
|
@@ -95,7 +96,8 @@ class Syslogger
|
|
95
96
|
buffer = ""
|
96
97
|
communication.bytes do |byte|
|
97
98
|
buffer.concat(byte)
|
98
|
-
if
|
99
|
+
# if the last byte we added is potentially part of an escape, we'll go ahead and add another byte
|
100
|
+
if buffer.bytesize >= self.max_octets && !['%'.ord,'\\'.ord].include?(byte)
|
99
101
|
s.log(MAPPING[severity],buffer)
|
100
102
|
buffer = ""
|
101
103
|
end
|
data/spec/syslogger_spec.rb
CHANGED
@@ -3,14 +3,14 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
describe "Syslogger" do
|
4
4
|
it "should log to the default syslog facility, with the default options" do
|
5
5
|
logger = Syslogger.new
|
6
|
-
Syslog.should_receive(:open).with($0, Syslog::LOG_PID | Syslog::LOG_CONS, nil).and_yield(syslog=
|
6
|
+
Syslog.should_receive(:open).with($0, Syslog::LOG_PID | Syslog::LOG_CONS, nil).and_yield(syslog=double("syslog", :mask= => true))
|
7
7
|
syslog.should_receive(:log).with(Syslog::LOG_WARNING, "Some message")
|
8
8
|
logger.warn "Some message"
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should log to the user facility, with specific options" do
|
12
12
|
logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
|
13
|
-
Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=
|
13
|
+
Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=double("syslog", :mask= => true))
|
14
14
|
syslog.should_receive(:log).with(Syslog::LOG_WARNING, "Some message")
|
15
15
|
logger.warn "Some message"
|
16
16
|
end
|
@@ -23,7 +23,7 @@ describe "Syslogger" do
|
|
23
23
|
it "should log #{logger_method} without raising an exception if called with a block" do
|
24
24
|
logger = Syslogger.new
|
25
25
|
logger.level = Logger.const_get(logger_method.upcase)
|
26
|
-
Syslog.stub
|
26
|
+
Syslog.stub(:open).and_yield(syslog=double("syslog", :mask= => true))
|
27
27
|
severity = Syslogger::MAPPING[Logger.const_get(logger_method.upcase)]
|
28
28
|
syslog.should_receive(:log).with(severity, "Some message that doesn't need to be in a block")
|
29
29
|
lambda {
|
@@ -44,13 +44,24 @@ describe "Syslogger" do
|
|
44
44
|
logger.send(logger_method.to_sym)
|
45
45
|
}.should_not raise_error
|
46
46
|
end
|
47
|
+
|
48
|
+
it "should log #{logger_method} without raising an exception if message splits on an escape" do
|
49
|
+
logger = Syslogger.new
|
50
|
+
logger.max_octets=100
|
51
|
+
msg="A"*99
|
52
|
+
msg+="%BBB"
|
53
|
+
lambda {
|
54
|
+
logger.send(logger_method.to_sym,msg)
|
55
|
+
}.should_not raise_error
|
56
|
+
end
|
57
|
+
|
47
58
|
end
|
48
59
|
|
49
60
|
%w{debug info warn error}.each do |logger_method|
|
50
61
|
it "should not log #{logger_method} when level is higher" do
|
51
62
|
logger = Syslogger.new
|
52
63
|
logger.level = Logger::FATAL
|
53
|
-
Syslog.should_not_receive(:open).with($0, Syslog::LOG_PID | Syslog::LOG_CONS, nil).and_yield(syslog=
|
64
|
+
Syslog.should_not_receive(:open).with($0, Syslog::LOG_PID | Syslog::LOG_CONS, nil).and_yield(syslog=double("syslog", :mask= => true))
|
54
65
|
syslog.should_not_receive(:log).with(Syslog::LOG_NOTICE, "Some message")
|
55
66
|
logger.send(logger_method.to_sym, "Some message")
|
56
67
|
end
|
@@ -58,7 +69,7 @@ describe "Syslogger" do
|
|
58
69
|
it "should not evaluate a block or log #{logger_method} when level is higher" do
|
59
70
|
logger = Syslogger.new
|
60
71
|
logger.level = Logger::FATAL
|
61
|
-
Syslog.should_not_receive(:open).with($0, Syslog::LOG_PID | Syslog::LOG_CONS, nil).and_yield(syslog=
|
72
|
+
Syslog.should_not_receive(:open).with($0, Syslog::LOG_PID | Syslog::LOG_CONS, nil).and_yield(syslog=double("syslog", :mask= => true))
|
62
73
|
syslog.should_not_receive(:log).with(Syslog::LOG_NOTICE, "Some message")
|
63
74
|
logger.send(logger_method.to_sym) { violated "This block should not have been called" }
|
64
75
|
end
|
@@ -67,7 +78,7 @@ describe "Syslogger" do
|
|
67
78
|
it "should respond to <<" do
|
68
79
|
logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
|
69
80
|
logger.should respond_to(:<<)
|
70
|
-
Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=
|
81
|
+
Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=double("syslog", :mask= => true))
|
71
82
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "yop")
|
72
83
|
logger << "yop"
|
73
84
|
end
|
@@ -75,7 +86,7 @@ describe "Syslogger" do
|
|
75
86
|
it "should respond to write" do
|
76
87
|
logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
|
77
88
|
logger.should respond_to(:write)
|
78
|
-
Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=
|
89
|
+
Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=double("syslog", :mask= => true))
|
79
90
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "yop")
|
80
91
|
logger.write "yop"
|
81
92
|
end
|
@@ -88,17 +99,17 @@ describe "Syslogger" do
|
|
88
99
|
@logger.should respond_to(:add)
|
89
100
|
end
|
90
101
|
it "should correctly log" do
|
91
|
-
Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=
|
102
|
+
Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=double("syslog", :mask= => true))
|
92
103
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
|
93
104
|
@logger.add(Logger::INFO, "message")
|
94
105
|
end
|
95
106
|
it "should take the message from the block if :message is nil" do
|
96
|
-
Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=
|
107
|
+
Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=double("syslog", :mask= => true))
|
97
108
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "my message")
|
98
109
|
@logger.add(Logger::INFO) { "my message" }
|
99
110
|
end
|
100
111
|
it "should use the given progname" do
|
101
|
-
Syslog.should_receive(:open).with("progname", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=
|
112
|
+
Syslog.should_receive(:open).with("progname", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=double("syslog", :mask= => true))
|
102
113
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
|
103
114
|
@logger.add(Logger::INFO, "message", "progname") { "my message" }
|
104
115
|
end
|
@@ -106,7 +117,7 @@ describe "Syslogger" do
|
|
106
117
|
it "should use the default progname when message is passed in progname" do
|
107
118
|
Syslog.should_receive(:open).
|
108
119
|
with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).
|
109
|
-
and_yield(syslog =
|
120
|
+
and_yield(syslog = double("syslog", :mask= => true))
|
110
121
|
|
111
122
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
|
112
123
|
@logger.add(Logger::INFO, nil, "message")
|
@@ -115,20 +126,20 @@ describe "Syslogger" do
|
|
115
126
|
it "should use the given progname if message is passed in block" do
|
116
127
|
Syslog.should_receive(:open).
|
117
128
|
with("progname", Syslog::LOG_PID, Syslog::LOG_USER).
|
118
|
-
and_yield(syslog =
|
129
|
+
and_yield(syslog = double("syslog", :mask= => true))
|
119
130
|
|
120
131
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
|
121
132
|
@logger.add(Logger::INFO, nil, "progname") { "message" }
|
122
133
|
end
|
123
134
|
|
124
135
|
it "should substitute '%' for '%%' before adding the :message" do
|
125
|
-
Syslog.stub(:open).and_yield(syslog=
|
136
|
+
Syslog.stub(:open).and_yield(syslog=double("syslog", :mask= => true))
|
126
137
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "%%me%%ssage%%")
|
127
138
|
@logger.add(Logger::INFO, "%me%ssage%")
|
128
139
|
end
|
129
140
|
|
130
141
|
it "should strip the :message" do
|
131
|
-
Syslog.stub(:open).and_yield(syslog=
|
142
|
+
Syslog.stub(:open).and_yield(syslog=double("syslog", :mask= => true))
|
132
143
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
|
133
144
|
@logger.add(Logger::INFO, "\n\nmessage ")
|
134
145
|
end
|
@@ -136,7 +147,7 @@ describe "Syslogger" do
|
|
136
147
|
it "should not raise exception if asked to log with a nil message and body" do
|
137
148
|
Syslog.should_receive(:open).
|
138
149
|
with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).
|
139
|
-
and_yield(syslog=
|
150
|
+
and_yield(syslog=double("syslog", :mask= => true))
|
140
151
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "")
|
141
152
|
lambda {
|
142
153
|
@logger.add(Logger::INFO, nil)
|
@@ -146,7 +157,7 @@ describe "Syslogger" do
|
|
146
157
|
it "should send an empty string if the message and block are nil" do
|
147
158
|
Syslog.should_receive(:open).
|
148
159
|
with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).
|
149
|
-
and_yield(syslog=
|
160
|
+
and_yield(syslog=double("syslog", :mask= => true))
|
150
161
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "")
|
151
162
|
@logger.add(Logger::INFO, nil)
|
152
163
|
end
|
@@ -155,7 +166,7 @@ describe "Syslogger" do
|
|
155
166
|
@logger.max_octets = 480
|
156
167
|
Syslog.should_receive(:open).
|
157
168
|
with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).
|
158
|
-
and_yield(syslog=
|
169
|
+
and_yield(syslog=double("syslog", :mask= => true))
|
159
170
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "a"*480).twice
|
160
171
|
@logger.add(Logger::INFO, "a"*960)
|
161
172
|
end
|
@@ -221,7 +232,7 @@ describe "Syslogger" do
|
|
221
232
|
|
222
233
|
it "should permanently change the ident string" do
|
223
234
|
@logger.ident = "new_ident"
|
224
|
-
Syslog.should_receive(:open).with("new_ident", Syslog::LOG_PID | Syslog::LOG_CONS, nil).and_yield(syslog=
|
235
|
+
Syslog.should_receive(:open).with("new_ident", Syslog::LOG_PID | Syslog::LOG_CONS, nil).and_yield(syslog=double("syslog", :mask= => true))
|
225
236
|
syslog.should_receive(:log)
|
226
237
|
@logger.warn("should get the new ident string")
|
227
238
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syslogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -101,3 +101,4 @@ summary: Dead simple Ruby Syslog logger
|
|
101
101
|
test_files:
|
102
102
|
- spec/spec_helper.rb
|
103
103
|
- spec/syslogger_spec.rb
|
104
|
+
has_rdoc:
|