syslogger 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -0
- data/lib/syslogger.rb +23 -8
- data/spec/syslogger_spec.rb +21 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -17,6 +17,9 @@ specify the facility and the syslog options.
|
|
17
17
|
# Will send all messages to the local0 facility, adding the process id in the message
|
18
18
|
logger = Syslogger.new("app_name", Syslog::LOG_PID, Syslog::LOG_LOCAL0)
|
19
19
|
|
20
|
+
# Optionally split messages to the specified number of bytes
|
21
|
+
logger.max_octets = 480
|
22
|
+
|
20
23
|
# Send messages that are at least of the Logger::INFO level
|
21
24
|
logger.level = Logger::INFO # use Logger levels
|
22
25
|
|
data/lib/syslogger.rb
CHANGED
@@ -4,9 +4,9 @@ require 'thread'
|
|
4
4
|
|
5
5
|
class Syslogger
|
6
6
|
|
7
|
-
VERSION = "1.4.
|
7
|
+
VERSION = "1.4.2"
|
8
8
|
|
9
|
-
attr_reader :level, :ident, :options, :facility
|
9
|
+
attr_reader :level, :ident, :options, :facility, :max_octets
|
10
10
|
|
11
11
|
MAPPING = {
|
12
12
|
Logger::DEBUG => Syslog::LOG_DEBUG,
|
@@ -76,8 +76,8 @@ class Syslogger
|
|
76
76
|
|
77
77
|
# Low level method to add a message.
|
78
78
|
# +severity+:: the level of the message. One of Logger::DEBUG, Logger::INFO, Logger::WARN, Logger::ERROR, Logger::FATAL, Logger::UNKNOWN
|
79
|
-
# +message+:: the message string.
|
80
|
-
# If nil, the method will call the block and use the result as the message string.
|
79
|
+
# +message+:: the message string.
|
80
|
+
# If nil, the method will call the block and use the result as the message string.
|
81
81
|
# If both are nil or no block is given, it will use the progname as per the behaviour of both the standard Ruby logger, and the Rails BufferedLogger.
|
82
82
|
# +progname+:: optionally, overwrite the program name that appears in the log message.
|
83
83
|
def add(severity, message = nil, progname = nil, &block)
|
@@ -85,14 +85,29 @@ class Syslogger
|
|
85
85
|
@mutex.synchronize do
|
86
86
|
Syslog.open(progname, @options, @facility) do |s|
|
87
87
|
s.mask = Syslog::LOG_UPTO(MAPPING[@level])
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
communication = clean(message || (block && block.call) || progname)
|
89
|
+
if self.max_octets
|
90
|
+
buffer = ""
|
91
|
+
communication.bytes do |byte|
|
92
|
+
buffer.concat(byte)
|
93
|
+
if buffer.bytesize >= self.max_octets
|
94
|
+
s.log(MAPPING[severity],buffer)
|
95
|
+
buffer = ""
|
96
|
+
end
|
97
|
+
end
|
98
|
+
s.log(MAPPING[severity],buffer) unless buffer.empty?
|
99
|
+
else
|
100
|
+
s.log(MAPPING[severity],communication)
|
101
|
+
end
|
92
102
|
end
|
93
103
|
end
|
94
104
|
end
|
95
105
|
|
106
|
+
# Set the max octets of the messages written to the log
|
107
|
+
def max_octets=(max_octets)
|
108
|
+
@max_octets = max_octets
|
109
|
+
end
|
110
|
+
|
96
111
|
# Sets the minimum level for messages to be written in the log.
|
97
112
|
# +level+:: one of <tt>Logger::DEBUG</tt>, <tt>Logger::INFO</tt>, <tt>Logger::WARN</tt>, <tt>Logger::ERROR</tt>, <tt>Logger::FATAL</tt>, <tt>Logger::UNKNOWN</tt>
|
98
113
|
def level=(level)
|
data/spec/syslogger_spec.rb
CHANGED
@@ -132,8 +132,29 @@ describe "Syslogger" do
|
|
132
132
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "my_app")
|
133
133
|
@logger.add(Logger::INFO, nil)
|
134
134
|
end
|
135
|
+
|
136
|
+
it "should split string over the max octet size" do
|
137
|
+
@logger.max_octets = 480
|
138
|
+
Syslog.should_receive(:open).
|
139
|
+
with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).
|
140
|
+
and_yield(syslog=mock("syslog", :mask= => true))
|
141
|
+
syslog.should_receive(:log).with(Syslog::LOG_INFO, "a"*480).twice
|
142
|
+
@logger.add(Logger::INFO, "a"*960)
|
143
|
+
end
|
135
144
|
end # describe "add"
|
136
145
|
|
146
|
+
describe "max_octets=" do
|
147
|
+
before(:each) do
|
148
|
+
@logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should set the max_octets for the logger" do
|
152
|
+
lambda { @logger.max_octets = 1 }.should change(@logger, :max_octets)
|
153
|
+
@logger.max_octets.should == 1
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
137
158
|
describe "level=" do
|
138
159
|
before(:each) do
|
139
160
|
@logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
|
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.
|
4
|
+
version: 1.4.2
|
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: 2013-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|