summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-26 11:15:06 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-26 11:15:06 +0000
commit9d00f3f536e40d13bfa8a80ace3c8ac1b92b18cd (patch)
tree9449afb645bcdd445be3181020ba8483c95a5dbf /ext
parent621da983093b0877d061c0fa081c0301ea8ffd3f (diff)
Add facility to Syslog::Logger.
* ext/syslog/lib/syslog/logger.rb (Syslog::Logger): Add facility to Syslog::Logger. [Fixes GH-305] patch by Max Shytikov https://github.com/ruby/ruby/pull/305 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/syslog/lib/syslog/logger.rb22
1 files changed, 18 insertions, 4 deletions
diff --git a/ext/syslog/lib/syslog/logger.rb b/ext/syslog/lib/syslog/logger.rb
index 1e1f9fe817..086f83c591 100644
--- a/ext/syslog/lib/syslog/logger.rb
+++ b/ext/syslog/lib/syslog/logger.rb
@@ -24,6 +24,14 @@ require 'logger'
# log = Syslog::Logger.new 'my_program'
# log.info 'this line will be logged via syslog(3)'
#
+# Also the facility may be set to specify the facility level which will be used:
+#
+# log.info 'this line will be logged using Syslog default facility level'
+#
+# log_local1 = Syslog::Logger.new 'my_program', Syslog::LOG_LOCAL1
+# log_local1.info 'this line will be logged using local1 facility level'
+#
+#
# You may need to perform some syslog.conf setup first. For a BSD machine add
# the following lines to /etc/syslog.conf:
#
@@ -168,17 +176,24 @@ class Syslog::Logger
attr_accessor :formatter
##
+ # The facility argument is used to specify what type of program is logging the message.
+
+ attr_accessor :facility
+
+ ##
# Fills in variables for Logger compatibility. If this is the first
# instance of Syslog::Logger, +program_name+ may be set to change the logged
- # program name.
+ # program name. The +facility+ may be set to specify the facility level which will be used.
#
# Due to the way syslog works, only one program name may be chosen.
- def initialize program_name = 'ruby'
+ def initialize program_name = 'ruby', facility = nil
@level = ::Logger::DEBUG
@formatter = Formatter.new
@@syslog ||= Syslog.open(program_name)
+
+ @facility = (facility || @@syslog.facility)
end
##
@@ -187,8 +202,7 @@ class Syslog::Logger
def add severity, message = nil, progname = nil, &block
severity ||= ::Logger::UNKNOWN
@level <= severity and
- @@syslog.log LEVEL_MAP[severity], '%s', formatter.call(severity, Time.now, progname, (message || block.call))
+ @@syslog.log( (LEVEL_MAP[severity] | @facility), '%s', formatter.call(severity, Time.now, progname, (message || block.call)) )
true
end
end
-