Module: MultiSync::Logging

Included in:
MultiSync
Defined in:
lib/multi_sync/logging.rb

Constant Summary collapse

MUTEX =
Mutex.new

Instance Method Summary collapse

Instance Method Details

#log(message, level = :debug) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/multi_sync/logging.rb', line 40

def log(message, level = :debug)
  # We're not in verbose mode so disable all non-info logs
  say_status :sync, message
  return if !MultiSync.verbose && level != :info
  MUTEX.synchronize do
    logger.send(level, message)
  end
end

#loggerObject

Retrieves the current MultiSync logger



9
10
11
# File 'lib/multi_sync/logging.rb', line 9

def logger
  @logger || initialize_logger
end

#logger=(new_logger) ⇒ Object

Sets the current MultiSync logger



14
15
16
# File 'lib/multi_sync/logging.rb', line 14

def logger=(new_logger)
  @logger = new_logger ? new_logger : Logger.new('/dev/null')
end

#say_status(status, message, log_status = true) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/multi_sync/logging.rb', line 29

def say_status(status, message, log_status = true)
  return if status_logger.nil?

  if defined?(Thor) && status_logger.is_a?(Thor)
    MUTEX.synchronize do
      status_logger.say_status status, message, log_status
    end
  end
end

#status_loggerObject

Retrieves the current MultiSync status_logger



19
20
21
# File 'lib/multi_sync/logging.rb', line 19

def status_logger
  @status_logger || initialize_status_logger
end

#status_logger=(new_status_logger) ⇒ Object

Sets the current MultiSync logger



24
25
26
# File 'lib/multi_sync/logging.rb', line 24

def status_logger=(new_status_logger)
  @status_logger = new_status_logger ? new_status_logger : nil
end