Class: JobManager::ApplicationSyslogLogger
- Inherits:
-
ApplicationLogger
- Object
- IO
- ApplicationLogger
- JobManager::ApplicationSyslogLogger
- Defined in:
- lib/jobmanager/applicationlogger.rb
Overview
This class provides a Logger interface and logs messages to syslog via the SysLogLogger gem. In addition, this class provides a string instance method which allows the caller to retrieve a concatenation of all the messages written to this logger. The level, user name, and job name are prepended to each message that is written to syslog. A number of the interface methods are implemented via the method_missing method.
Constant Summary
Constants inherited from ApplicationLogger
JobManager::ApplicationLogger::LEVEL_LOGGER_MAP
Instance Attribute Summary
Attributes inherited from ApplicationLogger
Instance Method Summary collapse
-
#add(severity, message = nil, &block) ⇒ Object
(also: #log)
Description: This method is akin to the Logger::add interface method.
-
#close ⇒ Object
Description: This method closes the connection to the syslog daemon.
-
#initialize(program_name, user_name, job_name = nil) ⇒ ApplicationSyslogLogger
constructor
Description: This method creates a new instance.
-
#string ⇒ Object
Returns: A string containing all mesages that were logged through this interface.
Methods inherited from ApplicationLogger
#record_exception, #record_tagged_exception, #write
Constructor Details
#initialize(program_name, user_name, job_name = nil) ⇒ ApplicationSyslogLogger
Description:
This method creates a new instance.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/jobmanager/applicationlogger.rb', line 75 def initialize(program_name, user_name, job_name = nil) super(job_name, user_name) @program_name = program_name @stringio = StringIO.new @logger = SyslogLogger.new(program_name) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object (private)
Description:
This method is intended to handle all shortcut methods (debug, warn, info, etc.), as well as the level attribute methods.
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/jobmanager/applicationlogger.rb', line 120 def method_missing(*args, &block) method = args.shift # if the method is a shortcut log method if (SyslogLogger::LOGGER_MAP.find() {|key, value| method == key}) # wrap the message (with the job and user names) wrap_record_send(method, (args.length > 0) ? args[0] : yield) else # otherwise forward the message directly on to the SyslogLogger instance. @logger.send(method, *args, &block) end end |
Instance Method Details
#add(severity, message = nil, &block) ⇒ Object Also known as: log
Description:
This method is akin to the Logger::add interface method.
100 101 102 |
# File 'lib/jobmanager/applicationlogger.rb', line 100 def add(severity, = nil, &block) wrap_record_send(LEVEL_LOGGER_MAP[severity], || yield) end |
#close ⇒ Object
Description:
This method closes the connection to the syslog daemon.
109 110 111 |
# File 'lib/jobmanager/applicationlogger.rb', line 109 def close if (Syslog.opened?) then Syslog.close() end end |
#string ⇒ Object
Returns:
A string containing all mesages that were logged through this interface.
92 93 94 |
# File 'lib/jobmanager/applicationlogger.rb', line 92 def string() return @stringio.string() end |