Permalink
Browse files

Merge 1.2.0 commits from crohr/syslogger.

  • Loading branch information...
2 parents 0373f71 + f1b9337 commit 5bf6c4596ee8db7bb132ca960d5a5e7f0658a229 Yuri Gadow committed Mar 10, 2010
Showing with 48 additions and 8 deletions.
  1. +1 −1 VERSION
  2. +13 −4 lib/syslogger.rb
  3. +32 −1 spec/syslogger_spec.rb
  4. +2 −2 syslogger.gemspec
View
@@ -1 +1 @@
-1.1.0
+1.2.0
View
@@ -35,13 +35,22 @@ def initialize(ident = $0, options = Syslog::LOG_PID | Syslog::LOG_CONS, facilit
%w{debug info warn error fatal unknown}.each do |logger_method|
define_method logger_method.to_sym do |message|
- Syslog.open(@ident, @options, @facility) { |s|
- s.mask = Syslog::LOG_UPTO(MAPPING[@level])
- s.log(MAPPING[Logger.const_get(logger_method.upcase)], message)
- }
+ add(Logger.const_get(logger_method.upcase), message)
end
end
+ def <<(msg)
+ add(Logger::INFO, msg)
+ end
+
+ def add(severity, message = nil, progname = nil, &block)
+ progname ||= @ident
+ Syslog.open(progname, @options, @facility) { |s|
+ s.mask = Syslog::LOG_UPTO(MAPPING[@level])
+ s.log(MAPPING[severity], (message || block.call))
+ }
+ end
+
def level=(logger_level)
@level = logger_level
end
View
@@ -25,5 +25,36 @@
Syslogger.new.should respond_to :close
end
- # TODO: test logger level
+ it "should respond to <<" do
+ logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
+ logger.should respond_to(:<<)
+ Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=mock("syslog", :mask= => true))
+ syslog.should_receive(:log).with(Syslog::LOG_INFO, "yop")
+ logger << "yop"
+ end
+
+ describe "add" do
+ before do
+ @logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
+ end
+ it "should respond to add" do
+ @logger.should respond_to(:add)
+ end
+ it "should correctly log" do
+ Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=mock("syslog", :mask= => true))
+ syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
+ @logger.add(Logger::INFO, "message")
+ end
+ it "should take the message from the block if :message is nil" do
+ Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=mock("syslog", :mask= => true))
+ syslog.should_receive(:log).with(Syslog::LOG_INFO, "my message")
+ @logger.add(Logger::INFO) { "my message" }
+ end
+ it "should use the given progname" do
+ Syslog.should_receive(:open).with("progname", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=mock("syslog", :mask= => true))
+ syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
+ @logger.add(Logger::INFO, "message", "progname") { "my message" }
+ end
+ end
+
end
View
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{syslogger}
- s.version = "1.1.0"
+ s.version = "1.2.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Cyril Rohr"]
- s.date = %q{2010-03-05}
+ s.date = %q{2010-03-10}
s.description = %q{Same as SyslogLogger, but without the ridiculous number of dependencies and with the possibility to specify the syslog facility}
s.email = %q{cyril.rohr@gmail.com}
s.extra_rdoc_files = [

0 comments on commit 5bf6c45

Please sign in to comment.