syslogger 1.2.3 → 1.2.4
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 +14 -6
- data/spec/syslogger_spec.rb +31 -13
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -19,6 +19,8 @@ Contrary to the SyslogLogger library, you can specify the facility and the syslo
|
|
19
19
|
logger.info "will appear"
|
20
20
|
logger.warn "will appear"
|
21
21
|
|
22
|
+
Documentation available at <http://rdoc.info/github/crohr/syslogger/master/file/README.rdoc>.
|
23
|
+
|
22
24
|
== Development
|
23
25
|
* Install +bundler+:
|
24
26
|
|
@@ -38,6 +40,7 @@ Contrary to the SyslogLogger library, you can specify the facility and the syslo
|
|
38
40
|
|
39
41
|
== Contributions
|
40
42
|
* crhym3
|
43
|
+
* theflow
|
41
44
|
|
42
45
|
== Copyright
|
43
46
|
|
data/lib/syslogger.rb
CHANGED
@@ -3,7 +3,7 @@ require 'logger'
|
|
3
3
|
|
4
4
|
class Syslogger
|
5
5
|
|
6
|
-
VERSION = "1.2.
|
6
|
+
VERSION = "1.2.4"
|
7
7
|
|
8
8
|
attr_reader :level, :ident, :options, :facility
|
9
9
|
|
@@ -65,13 +65,18 @@ class Syslogger
|
|
65
65
|
|
66
66
|
# Low level method to add a message.
|
67
67
|
# +severity+:: the level of the message. One of Logger::DEBUG, Logger::INFO, Logger::WARN, Logger::ERROR, Logger::FATAL, Logger::UNKNOWN
|
68
|
-
# +message+:: the message string.
|
69
|
-
#
|
68
|
+
# +message+:: the message string.
|
69
|
+
# If nil, the method will call the block and use the result as the message string.
|
70
|
+
# 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.
|
71
|
+
# +progname+:: optionally, overwrite the program name that appears in the log message.
|
70
72
|
def add(severity, message = nil, progname = nil, &block)
|
71
73
|
progname ||= @ident
|
72
74
|
Syslog.open(progname, @options, @facility) { |s|
|
73
75
|
s.mask = Syslog::LOG_UPTO(MAPPING[@level])
|
74
|
-
s.log(
|
76
|
+
s.log(
|
77
|
+
MAPPING[severity],
|
78
|
+
clean(message || (block && block.call) || progname)
|
79
|
+
)
|
75
80
|
}
|
76
81
|
end
|
77
82
|
|
@@ -85,7 +90,10 @@ class Syslogger
|
|
85
90
|
|
86
91
|
# Borrowed from SyslogLogger.
|
87
92
|
def clean(message)
|
88
|
-
|
89
|
-
message.strip
|
93
|
+
message = message.to_s.dup
|
94
|
+
message.strip!
|
95
|
+
message.gsub!(/%/, '%%') # syslog(3) freaks on % (printf)
|
96
|
+
message.gsub!(/\e\[[^m]*m/, '') # remove useless ansi color codes
|
97
|
+
message
|
90
98
|
end
|
91
99
|
end
|
data/spec/syslogger_spec.rb
CHANGED
@@ -7,20 +7,20 @@ describe "Syslogger" do
|
|
7
7
|
syslog.should_receive(:log).with(Syslog::LOG_NOTICE, "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
13
|
Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=mock("syslog", :mask= => true))
|
14
14
|
syslog.should_receive(:log).with(Syslog::LOG_NOTICE, "Some message")
|
15
15
|
logger.warn "Some message"
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
%w{debug info warn error fatal unknown}.each do |logger_method|
|
19
19
|
it "should respond to the #{logger_method.inspect} method" do
|
20
20
|
Syslogger.new.should respond_to logger_method.to_sym
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it "should respond to <<" do
|
25
25
|
logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
|
26
26
|
logger.should respond_to(:<<)
|
@@ -28,7 +28,7 @@ describe "Syslogger" do
|
|
28
28
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "yop")
|
29
29
|
logger << "yop"
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
describe "add" do
|
33
33
|
before do
|
34
34
|
@logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
|
@@ -51,7 +51,7 @@ describe "Syslogger" do
|
|
51
51
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
|
52
52
|
@logger.add(Logger::INFO, "message", "progname") { "my message" }
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
it "should substitute '%' for '%%' before adding the :message" do
|
56
56
|
Syslog.stub(:open).and_yield(syslog=mock("syslog", :mask= => true))
|
57
57
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "%%me%%ssage%%")
|
@@ -63,30 +63,48 @@ describe "Syslogger" do
|
|
63
63
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
|
64
64
|
@logger.add(Logger::INFO, "\n\nmessage ")
|
65
65
|
end
|
66
|
+
|
67
|
+
it "should not raise exception if asked to log with a nil message and body" do
|
68
|
+
Syslog.should_receive(:open).
|
69
|
+
with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).
|
70
|
+
and_yield(syslog=mock("syslog", :mask= => true))
|
71
|
+
syslog.should_receive(:log).with(Syslog::LOG_INFO, "my_app")
|
72
|
+
lambda {
|
73
|
+
@logger.add(Logger::INFO, nil)
|
74
|
+
}.should_not raise_error
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should use given progname as the message if the message and block are nil" do
|
78
|
+
Syslog.should_receive(:open).
|
79
|
+
with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).
|
80
|
+
and_yield(syslog=mock("syslog", :mask= => true))
|
81
|
+
syslog.should_receive(:log).with(Syslog::LOG_INFO, "my_app")
|
82
|
+
@logger.add(Logger::INFO, nil)
|
83
|
+
end
|
66
84
|
end # describe "add"
|
67
|
-
|
85
|
+
|
68
86
|
describe ":level? methods" do
|
69
87
|
before(:each) do
|
70
88
|
@logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
|
71
89
|
end
|
72
|
-
|
90
|
+
|
73
91
|
%w{debug info warn error fatal}.each do |logger_method|
|
74
92
|
it "should respond to the #{logger_method}? method" do
|
75
93
|
@logger.should respond_to "#{logger_method}?".to_sym
|
76
94
|
end
|
77
95
|
end
|
78
|
-
|
96
|
+
|
79
97
|
it "should not have unknown? method" do
|
80
98
|
@logger.should_not respond_to :unknown?
|
81
99
|
end
|
82
|
-
|
100
|
+
|
83
101
|
it "should return true for all methods" do
|
84
102
|
@logger.level = Logger::DEBUG
|
85
103
|
%w{debug info warn error fatal}.each do |logger_method|
|
86
104
|
@logger.send("#{logger_method}?").should be_true
|
87
105
|
end
|
88
106
|
end
|
89
|
-
|
107
|
+
|
90
108
|
it "should return true for all except debug?" do
|
91
109
|
@logger.level = Logger::INFO
|
92
110
|
%w{info warn error fatal}.each do |logger_method|
|
@@ -94,7 +112,7 @@ describe "Syslogger" do
|
|
94
112
|
end
|
95
113
|
@logger.debug?.should be_false
|
96
114
|
end
|
97
|
-
|
115
|
+
|
98
116
|
it "should return true for warn?, error? and fatal? when WARN" do
|
99
117
|
@logger.level = Logger::WARN
|
100
118
|
%w{warn error fatal}.each do |logger_method|
|
@@ -104,7 +122,7 @@ describe "Syslogger" do
|
|
104
122
|
@logger.send("#{logger_method}?").should be_false
|
105
123
|
end
|
106
124
|
end
|
107
|
-
|
125
|
+
|
108
126
|
it "should return true for error? and fatal? when ERROR" do
|
109
127
|
@logger.level = Logger::ERROR
|
110
128
|
%w{error fatal}.each do |logger_method|
|
@@ -114,7 +132,7 @@ describe "Syslogger" do
|
|
114
132
|
@logger.send("#{logger_method}?").should be_false
|
115
133
|
end
|
116
134
|
end
|
117
|
-
|
135
|
+
|
118
136
|
it "should return true only for fatal? when FATAL" do
|
119
137
|
@logger.level = Logger::FATAL
|
120
138
|
@logger.fatal?.should be_true
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 1.2.
|
8
|
+
- 4
|
9
|
+
version: 1.2.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Cyril Rohr
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-08 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|