Module: Logging

Overview

Logging function module

Defined Under Namespace

Classes: MultiDelegator

Constant Summary collapse

@@level =
Logger::DEBUG

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



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

#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

#set_level(level) ⇒ Object

Set log level.

Parameters:

  • level (Fixnum)

    Log level for Logger object.



44
45
46
# File 'lib/sony_camera_remote_api/logging.rb', line 44

def set_level(level)
  @@level = level
end

#set_output(*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 set_output(*log_file)
  Logging.log_file self.class.name, log_file
end