Class: Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/zonesync/logger.rb

Class Method Summary collapse

Class Method Details

.log(method, args, dry_run: false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/zonesync/logger.rb', line 5

def self.log method, args, dry_run: false
  loggers = [::Logger.new(STDOUT)]

  if !dry_run
    FileUtils.mkdir_p("log")
    loggers << ::Logger.new("log/zonesync.log")
  end

  loggers.each do |logger|
    operation = case args
    when Array
      args.map { |h| h.values.join(" ") }.join(" -> ")
    when Hash
      args.values.join(" ")
    else
      raise args.inspect
    end
    logger.info "Zonesync: #{method.capitalize} #{operation}"
  end
end