syslogger 1.4.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/syslogger.rb +6 -2
  2. data/spec/syslogger_spec.rb +21 -3
  3. metadata +2 -2
data/lib/syslogger.rb CHANGED
@@ -4,7 +4,7 @@ require 'thread'
4
4
 
5
5
  class Syslogger
6
6
 
7
- VERSION = "1.4.2"
7
+ VERSION = "1.5.0"
8
8
 
9
9
  attr_reader :level, :ident, :options, :facility, :max_octets
10
10
 
@@ -81,11 +81,15 @@ class Syslogger
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)
84
+ if message.nil? && block.nil? && !progname.nil?
85
+ message, progname = progname, nil
86
+ end
84
87
  progname ||= @ident
88
+
85
89
  @mutex.synchronize do
86
90
  Syslog.open(progname, @options, @facility) do |s|
87
91
  s.mask = Syslog::LOG_UPTO(MAPPING[@level])
88
- communication = clean(message || (block && block.call) || progname)
92
+ communication = clean(message || block && block.call)
89
93
  if self.max_octets
90
94
  buffer = ""
91
95
  communication.bytes do |byte|
@@ -103,6 +103,24 @@ describe "Syslogger" do
103
103
  @logger.add(Logger::INFO, "message", "progname") { "my message" }
104
104
  end
105
105
 
106
+ it "should use the default progname when message is passed in progname" do
107
+ Syslog.should_receive(:open).
108
+ with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).
109
+ and_yield(syslog = mock("syslog", :mask= => true))
110
+
111
+ syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
112
+ @logger.add(Logger::INFO, nil, "message")
113
+ end
114
+
115
+ it "should use the given progname if message is passed in block" do
116
+ Syslog.should_receive(:open).
117
+ with("progname", Syslog::LOG_PID, Syslog::LOG_USER).
118
+ and_yield(syslog = mock("syslog", :mask= => true))
119
+
120
+ syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
121
+ @logger.add(Logger::INFO, nil, "progname") { "message" }
122
+ end
123
+
106
124
  it "should substitute '%' for '%%' before adding the :message" do
107
125
  Syslog.stub(:open).and_yield(syslog=mock("syslog", :mask= => true))
108
126
  syslog.should_receive(:log).with(Syslog::LOG_INFO, "%%me%%ssage%%")
@@ -119,17 +137,17 @@ describe "Syslogger" do
119
137
  Syslog.should_receive(:open).
120
138
  with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).
121
139
  and_yield(syslog=mock("syslog", :mask= => true))
122
- syslog.should_receive(:log).with(Syslog::LOG_INFO, "my_app")
140
+ syslog.should_receive(:log).with(Syslog::LOG_INFO, "")
123
141
  lambda {
124
142
  @logger.add(Logger::INFO, nil)
125
143
  }.should_not raise_error
126
144
  end
127
145
 
128
- it "should use given progname as the message if the message and block are nil" do
146
+ it "should send an empty string if the message and block are nil" do
129
147
  Syslog.should_receive(:open).
130
148
  with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).
131
149
  and_yield(syslog=mock("syslog", :mask= => true))
132
- syslog.should_receive(:log).with(Syslog::LOG_INFO, "my_app")
150
+ syslog.should_receive(:log).with(Syslog::LOG_INFO, "")
133
151
  @logger.add(Logger::INFO, nil)
134
152
  end
135
153
 
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.2
4
+ version: 1.5.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: 2013-02-10 00:00:00.000000000 Z
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake