Class: Itly::Loggers

Inherits:
Object
  • Object
show all
Defined in:
lib/itly/loggers.rb

Overview

Loggers class, provide default usual loggers for convenience

Class Method Summary collapse

Class Method Details

.itly_dot_logLogger

Logger to log into ‘itly.log’ file on the current directory

Returns:

  • (Logger)

    the logger



13
14
15
# File 'lib/itly/loggers.rb', line 13

def self.itly_dot_log
  Logger.new 'itly.log'
end

.nil_loggerNilClass

No logger

Returns:

  • (NilClass)

    nothing



31
32
33
# File 'lib/itly/loggers.rb', line 31

def self.nil_logger
  nil
end

.std_outLogger

Logger to log to standard out

Returns:

  • (Logger)

    the logger



22
23
24
# File 'lib/itly/loggers.rb', line 22

def self.std_out
  Logger.new $stdout
end

.vars_to_log(vars) ⇒ String

Shorthand to filter variables in a log message

Check if the variable has a value, and return a list for the log message

Parameters:

  • vars: (Hash)

    list of variables

Returns:

  • (String)

    log message



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/itly/loggers.rb', line 43

def self.vars_to_log(vars)
  vars.collect do |name, value|
    next if value.nil?

    if value.is_a?(Hash) || value.is_a?(Array)
      "#{name}: #{value}" if value.any?
    else
      "#{name}: #{value}"
    end
  end.compact.join ', '
end