Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ST: Updated gem with new yell adapter syntax

  • Loading branch information...
commit cd936bdddda167326fcb18693804b73cc7c31610 1 parent 236fa43
Rudolf Schmidt authored
7 lib/yell-adapters-syslog.rb
View
@@ -21,13 +21,10 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+module Yell #:nodoc:
+end
require 'syslog'
-
require 'yell'
require File.dirname(__FILE__) + '/yell/adapters/syslog'
-
-module Yell #:nodoc:
-end
-
105 lib/yell/adapters/syslog.rb
View
@@ -56,29 +56,47 @@ class Syslog < Yell::Adapters::Base
:local7 => ::Syslog::LOG_LOCAL7
}
- def initialize( options = {}, &block )
- ident options[:ident] || $0
- options options[:options] || [:pid, :cons]
- facility options[:facility]
-
- super( options, &block )
+ setup do |options|
+ self.ident = options[:ident] || $0
+ self.options = options[:options] || [:pid, :cons]
+ self.facility = options[:facility]
end
- def stream
- @stream ||= _new_stream
+ write do |event|
+ stream.log( SeverityMap[event.level], clean(event.message) )
end
- def close
- @stream.close if @stream.respond_to? :close
- rescue
- # do nothing
- ensure
- @stream = nil
+ close do
+ begin
+ @stream.close if @stream.respond_to? :close
+ rescue Exception
+ # do nothing
+ ensure
+ @stream = nil
+ end
end
- # Identify the calling program
+
+ # Access the Syslog ident
+ attr_accessor :ident
+
+ # Access the Syslog options
+ attr_reader :options
+
+ # Access the Syslog facility
+ attr_reader :facility
+
+
+ # Deprecated: use :ident= in future
def ident( val = nil )
- @ident = val
+ if val.nil?
+ @ident
+ else
+ # deprecate, but should still work
+ Yell._deprecate( "0.6.0", "Use :ident= for setting the Syslog ident" )
+
+ self.ident = val
+ end
end
# Set the log facility for Syslog
@@ -86,48 +104,69 @@ def ident( val = nil )
# See {Yell::Adapters::Syslog::OptionMap OptionMap} for allowed values.
#
# @example Direct or Symbol
- # facility( Syslog::LOG_NDELAY )
- # facility( :ndelay )
+ # options = Syslog::LOG_CONS
+ # options = :cons
#
# @example Multiple
- # facility( :ndelay, Syslog::LOG_NDELAY ):
- def options( *values )
- @syslog_options = values.flatten.map do |v|
+ # options = [:ndelay, Syslog::LOG_NDELAY]
+ def options=( *values )
+ @options = values.flatten.map do |v|
v.is_a?(Symbol) ? OptionMap[v] : v
end.inject { |a, b| a | b }
end
+ # Deprecated: use options= in future
+ def options( *values )
+ if values.empty?
+ @options
+ else
+ # deprecate, but should still work
+ Yell._deprecate( "0.6.0", "Use :options= for setting the Syslog options" )
+
+ self.options = values
+ end
+ end
+
+
# Set the log facility for Syslog
#
# See {Yell::Adapters::Syslog::FacilityMap FacilityMap} for allowed values.
+ #
# @example Direct or Symbol
- # facility( :user )
- # facility( Syslog::LOG_CONSOLE )
+ # facility = :user
+ # facility = Syslog::LOG_CONSOLE
#
# @example Multiple
- # facility( :user, Syslog::LOG_CONSOLE )
- def facility( *values )
+ # facility = [:user, Syslog::LOG_CONSOLE]
+ def facility=( *values )
@facility = values.flatten.map do |v|
v.is_a?(Symbol) ? FacilityMap[v] : v
end.inject { |a, b| a | b }
end
+ # Deprecated, use facility= in future
+ def facility( *values )
+ if values.empty?
+ @facility
+ else
+ # deprecate, but should still work
+ Yell._deprecate( "0.6.0", "Use :facility= for setting the Syslog facility" )
+
+ self.facility = values
+ end
+ end
- private
- def write!( event )
- stream.log( SeverityMap[event.level], clean(event.message) )
- rescue Exception => e
- close
+ private
- # re-raise the exception
- raise( e )
+ def stream
+ @stream ||= _new_stream
end
def _new_stream
return ::Syslog if ::Syslog.opened?
- ::Syslog.open( @ident, @syslog_options, @facility )
+ ::Syslog.open( @ident, @options, @facility )
end
# Borrowed from [SyslogLogger](https://github.com/seattlerb/sysloglogger)
16 spec/yell/adapters/syslog_spec.rb
View
@@ -25,9 +25,9 @@
context "a new Yell::Adapters::Syslog instance" do
subject { Yell::Adapters::Syslog.new }
- it { subject.instance_variable_get(:@ident).should == $0 }
- it { subject.instance_variable_get(:@syslog_options).should == (Syslog::LOG_PID | Syslog::LOG_CONS) }
- it { subject.instance_variable_get(:@facility).should be_nil }
+ it { subject.ident.should == $0 }
+ it { subject.options.should == (Syslog::LOG_PID | Syslog::LOG_CONS) }
+ it { subject.facility.should be_nil }
end
context "OptionMap" do
@@ -75,7 +75,7 @@
it "should be passed" do
mock.proxy( Syslog ).open( "my ident", anything, anything )
- subject.ident "my ident"
+ subject.ident = "my ident"
subject.write Yell::Event.new("INFO", "Hello World")
end
end
@@ -86,14 +86,14 @@
it "should be passed" do
mock.proxy( Syslog ).open( anything, Syslog::LOG_NDELAY, anything )
- subject.options :ndelay
+ subject.options = :ndelay
subject.write Yell::Event.new("INFO", "Hello World")
end
it "should work with multiple params" do
mock.proxy( Syslog ).open( anything, Syslog::LOG_PID|Syslog::LOG_NDELAY, anything )
- subject.options :pid, :ndelay
+ subject.options = [:pid, :ndelay]
subject.write Yell::Event.new("INFO", "Hello World")
end
end
@@ -104,14 +104,14 @@
it "should be passed" do
mock.proxy( Syslog ).open( anything, anything, Syslog::LOG_USER )
- subject.facility :user
+ subject.facility = :user
subject.write Yell::Event.new("INFO", "Hello World")
end
it "should work with multiple params" do
mock.proxy( Syslog ).open( anything, anything, Syslog::LOG_DAEMON|Syslog::LOG_USER )
- subject.facility :daemon, :user
+ subject.facility = [:daemon, :user]
subject.write Yell::Event.new("INFO", "Hello World")
end
end
2  yell-adapters-syslog.gemspec
View
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_runtime_dependency "yell", "~> 0.4"
+ s.add_runtime_dependency "yell", "~> 0.6"
s.add_development_dependency "rspec"
s.add_development_dependency "rr"
end
Please sign in to comment.
Something went wrong with that request. Please try again.