Module: Logging

Overview

Logging function module

Defined Under Namespace

Classes: MultiDelegator

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configure_logger_for(classname) ⇒ Object

Configure Logger instance for the user class.

  1. create Logger instance with given log file and sterams

  2. 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

#logLogger

Get Logger class instance for the user class.

Returns:

  • (Logger)

    Logging class instance



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.

Parameters:

  • log_file (String, IO, Array<String, IO>)

    file name or stream to output log.



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