Class: SyslogRuby::Logger
- Inherits:
-
Object
- Object
- SyslogRuby::Logger
- Defined in:
- lib/syslog_ruby/logger.rb
Constant Summary collapse
- @@facilities =
{}
- @@severities =
{}
Instance Attribute Summary collapse
-
#facility ⇒ Object
Returns the value of attribute facility.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#ident ⇒ Object
Returns the value of attribute ident.
-
#log_uri ⇒ Object
Returns the value of attribute log_uri.
-
#mask ⇒ Object
Returns the value of attribute mask.
-
#socket ⇒ Object
Returns the value of attribute socket.
Class Method Summary collapse
Instance Method Summary collapse
- #_configure_facility(facility) ⇒ Object
- #close ⇒ Object
-
#initialize(ident = 'ruby', facility = Facility::LOCAL6, options = {}) ⇒ Logger
constructor
A new instance of Logger.
- #log(level, message, *message_args) ⇒ Object
- #LOG_MASK(level) ⇒ Object
- #LOG_UPTO(level) ⇒ Object
- #opened? ⇒ Boolean
- #options ⇒ Object
- #reopen(*args) ⇒ Object
Constructor Details
#initialize(ident = 'ruby', facility = Facility::LOCAL6, options = {}) ⇒ Logger
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/syslog_ruby/logger.rb', line 26 def initialize(ident = 'ruby', facility = Facility::LOCAL6, = {}) @ident = "#{ident}[#{$$}]" @facility = _configure_facility(facility) @mask = LOG_UPTO(Severity::DEBUG) @log_uri = .fetch(:uri, 'testing') @hostname = Socket.gethostname.split('.').first _open end |
Instance Attribute Details
#facility ⇒ Object
Returns the value of attribute facility.
5 6 7 |
# File 'lib/syslog_ruby/logger.rb', line 5 def facility @facility end |
#hostname ⇒ Object
Returns the value of attribute hostname.
5 6 7 |
# File 'lib/syslog_ruby/logger.rb', line 5 def hostname @hostname end |
#ident ⇒ Object
Returns the value of attribute ident.
5 6 7 |
# File 'lib/syslog_ruby/logger.rb', line 5 def ident @ident end |
#log_uri ⇒ Object
Returns the value of attribute log_uri.
5 6 7 |
# File 'lib/syslog_ruby/logger.rb', line 5 def log_uri @log_uri end |
#mask ⇒ Object
Returns the value of attribute mask.
5 6 7 |
# File 'lib/syslog_ruby/logger.rb', line 5 def mask @mask end |
#socket ⇒ Object
Returns the value of attribute socket.
5 6 7 |
# File 'lib/syslog_ruby/logger.rb', line 5 def socket @socket end |
Class Method Details
.setup_severity_methods ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/syslog_ruby/logger.rb', line 7 def setup_severity_methods SyslogRuby::Severity.constants.each do |level_name| level = SyslogRuby::Severity.const_get level_name define_method(level_name.downcase) do |*args| = args.shift facility = args.shift || send(:facility) _log(facility, level, ) end end end |
Instance Method Details
#_configure_facility(facility) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/syslog_ruby/logger.rb', line 37 def _configure_facility(facility) case facility when Integer || Fixnum facility when Symbol || String Facility[Facility] else Facility::NONE end end |
#close ⇒ Object
60 61 62 63 |
# File 'lib/syslog_ruby/logger.rb', line 60 def close raise RuntimeError.new "syslog not open" if socket.closed? socket.close end |
#log(level, message, *message_args) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/syslog_ruby/logger.rb', line 48 def log(level, , *) level = case level when Integer || Fixnum level when Symbol || String Severity[level] else Severity::INFO end _log(facility, level, , *) end |
#LOG_MASK(level) ⇒ Object
69 70 71 |
# File 'lib/syslog_ruby/logger.rb', line 69 def LOG_MASK(level) Severity[level] end |
#LOG_UPTO(level) ⇒ Object
73 74 75 76 77 |
# File 'lib/syslog_ruby/logger.rb', line 73 def LOG_UPTO(level) (0...Severity[level]).inject(Integer(0)) do |mask, i| mask|i end end |
#opened? ⇒ Boolean
79 80 81 |
# File 'lib/syslog_ruby/logger.rb', line 79 def opened? socket && !socket.closed? end |
#options ⇒ Object
83 84 85 |
# File 'lib/syslog_ruby/logger.rb', line 83 def 0 end |
#reopen(*args) ⇒ Object
65 66 67 |
# File 'lib/syslog_ruby/logger.rb', line 65 def reopen(*args) close && _open end |