Module: Logging
- Included in:
- SonyCameraRemoteAPI::Camera, SonyCameraRemoteAPI::CameraAPIGroupManager, SonyCameraRemoteAPI::CameraAPIManager, SonyCameraRemoteAPI::RawAPIManager, SonyCameraRemoteAPI::Retrying
- Defined in:
- lib/sony_camera_remote_api/logging.rb
Overview
Logging function module
Defined Under Namespace
Classes: MultiDelegator
Constant Summary collapse
- @@level =
Logger::DEBUG
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.
-
#set_level(level) ⇒ Object
Set log level.
-
#set_output(*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
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/sony_camera_remote_api/logging.rb', line 74 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.level = @@level logger end |
.log_file(classname, log_file) ⇒ Object
Set log files and streams. Logger class instance is re-created.
61 62 63 64 |
# File 'lib/sony_camera_remote_api/logging.rb', line 61 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
67 68 69 |
# File 'lib/sony_camera_remote_api/logging.rb', line 67 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 |
#set_level(level) ⇒ Object
Set log level.
44 45 46 |
# File 'lib/sony_camera_remote_api/logging.rb', line 44 def set_level(level) @@level = level end |