syslogger 1.2.6 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -5
- data/lib/syslogger.rb +7 -1
- data/spec/syslogger_spec.rb +27 -0
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -40,11 +40,7 @@ Documentation available at <http://rdoc.info/github/crohr/syslogger/master/file/
|
|
40
40
|
|
41
41
|
== Contributions
|
42
42
|
|
43
|
-
|
44
|
-
* theflow
|
45
|
-
* smulube
|
46
|
-
* levent
|
47
|
-
* Flameeyes
|
43
|
+
See <https://github.com/crohr/syslogger/contributors>.
|
48
44
|
|
49
45
|
== Copyright
|
50
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.7"
|
7
7
|
|
8
8
|
attr_reader :level, :ident, :options, :facility
|
9
9
|
|
@@ -50,6 +50,7 @@ class Syslogger
|
|
50
50
|
# Accepting *args as message could be nil.
|
51
51
|
# Default params not supported in ruby 1.8.7
|
52
52
|
define_method logger_method.to_sym do |*args, &block|
|
53
|
+
return true if @level > Logger.const_get(logger_method.upcase)
|
53
54
|
message = args.first || block && block.call
|
54
55
|
add(Logger.const_get(logger_method.upcase), message)
|
55
56
|
end
|
@@ -61,6 +62,11 @@ class Syslogger
|
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
65
|
+
# Log a message at the Logger::INFO level. Useful for use with Rack::CommonLogger
|
66
|
+
def write(msg)
|
67
|
+
add(Logger::INFO, msg)
|
68
|
+
end
|
69
|
+
|
64
70
|
# Logs a message at the Logger::INFO level.
|
65
71
|
def <<(msg)
|
66
72
|
add(Logger::INFO, msg)
|
data/spec/syslogger_spec.rb
CHANGED
@@ -22,6 +22,7 @@ describe "Syslogger" do
|
|
22
22
|
|
23
23
|
it "should log #{logger_method} without raising an exception if called with a block" do
|
24
24
|
logger = Syslogger.new
|
25
|
+
logger.level = Logger.const_get(logger_method.upcase)
|
25
26
|
Syslog.stub!(:open).and_yield(syslog=mock("syslog", :mask= => true))
|
26
27
|
severity = Syslogger::MAPPING[Logger.const_get(logger_method.upcase)]
|
27
28
|
syslog.should_receive(:log).with(severity, "Some message that doesn't need to be in a block")
|
@@ -45,6 +46,24 @@ describe "Syslogger" do
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
49
|
+
%w{debug info warn error}.each do |logger_method|
|
50
|
+
it "should not log #{logger_method} when level is higher" do
|
51
|
+
logger = Syslogger.new
|
52
|
+
logger.level = Logger::FATAL
|
53
|
+
Syslog.should_not_receive(:open).with($0, Syslog::LOG_PID | Syslog::LOG_CONS, nil).and_yield(syslog=mock("syslog", :mask= => true))
|
54
|
+
syslog.should_not_receive(:log).with(Syslog::LOG_NOTICE, "Some message")
|
55
|
+
logger.send(logger_method.to_sym, "Some message")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not evaluate a block or log #{logger_method} when level is higher" do
|
59
|
+
logger = Syslogger.new
|
60
|
+
logger.level = Logger::FATAL
|
61
|
+
Syslog.should_not_receive(:open).with($0, Syslog::LOG_PID | Syslog::LOG_CONS, nil).and_yield(syslog=mock("syslog", :mask= => true))
|
62
|
+
syslog.should_not_receive(:log).with(Syslog::LOG_NOTICE, "Some message")
|
63
|
+
logger.send(logger_method.to_sym) { violated "This block should not have been called" }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
48
67
|
it "should respond to <<" do
|
49
68
|
logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
|
50
69
|
logger.should respond_to(:<<)
|
@@ -53,6 +72,14 @@ describe "Syslogger" do
|
|
53
72
|
logger << "yop"
|
54
73
|
end
|
55
74
|
|
75
|
+
it "should respond to write" do
|
76
|
+
logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
|
77
|
+
logger.should respond_to(:write)
|
78
|
+
Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=mock("syslog", :mask= => true))
|
79
|
+
syslog.should_receive(:log).with(Syslog::LOG_INFO, "yop")
|
80
|
+
logger.write "yop"
|
81
|
+
end
|
82
|
+
|
56
83
|
describe "add" do
|
57
84
|
before do
|
58
85
|
@logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syslogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 7
|
10
|
+
version: 1.2.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Cyril Rohr
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-03-19 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|