Module: Logging
- Included in:
- SonyCameraRemoteAPI::Camera, SonyCameraRemoteAPI::CameraAPIGroupManager, SonyCameraRemoteAPI::CameraAPIManager, SonyCameraRemoteAPI::RawAPIManager
- Defined in:
- lib/sony_camera_remote_api/logging.rb
Overview
Logging function module
Defined Under Namespace
Classes: MultiDelegator
Class Method Summary collapse
-
.configure_logger_for(classname) ⇒ Object
Configure Logger instance for the user class.
-
.log_file(classname, log_file) ⇒ Object
Set log files and streams.
-
.logger_for(classname) ⇒ Object
Get Logger class instance or create it for the user class.
Instance Method Summary collapse
-
#log ⇒ Logger
Get Logger class instance for the user class.
-
#output_to(*log_file) ⇒ void
Set file name or stream to output log.
Class Method Details
.configure_logger_for(classname) ⇒ Object
Configure Logger instance for the user class.
-
create Logger instance with given log file and sterams
-
set progname to user class name
66 67 68 69 70 71 72 73 74 |
# File 'lib/sony_camera_remote_api/logging.rb', line 66 def configure_logger_for(classname) @log_file.compact! fios = @log_file.map do |f| f.is_a?(String) ? File.open(f, 'a') : f end logger = Logger.new MultiDelegator.delegate(:write, :close).to(*fios) logger.progname = classname.split('::')[-1] logger end |
.log_file(classname, log_file) ⇒ Object
Set log files and streams. Logger class instance is re-created.
53 54 55 56 |
# File 'lib/sony_camera_remote_api/logging.rb', line 53 def log_file(classname, log_file) @log_file = Array(log_file) @loggers[classname] = nil end |
.logger_for(classname) ⇒ Object
Get Logger class instance or create it for the user class
59 60 61 |
# File 'lib/sony_camera_remote_api/logging.rb', line 59 def logger_for(classname) @loggers[classname] ||= configure_logger_for(classname) end |
Instance Method Details
#log ⇒ Logger
Get Logger class instance for the user class.
29 30 31 |
# File 'lib/sony_camera_remote_api/logging.rb', line 29 def log @logger ||= Logging.logger_for(self.class.name) end |
#output_to(*log_file) ⇒ void
This method returns an undefined value.
Set file name or stream to output log. Log file is common in each user class.
38 39 40 |
# File 'lib/sony_camera_remote_api/logging.rb', line 38 def output_to(*log_file) Logging.log_file self.class.name, log_file end |