Class: Navvy::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/navvy/log.rb

Defined Under Namespace

Classes: LoggerNotFound

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerSymbol?

Default logger

Returns:

  • (Symbol, nil)

    logger



15
16
17
# File 'lib/navvy/log.rb', line 15

def self.logger
  @logger || Navvy.configuration.logger
end

.quiettrue, false

Be quiet?

Returns:

  • (true, false)

    quiet



24
25
26
# File 'lib/navvy/log.rb', line 24

def quiet
  @quiet
end

Class Method Details

.info(message, color = nil) ⇒ Object

Pass a log to the logger. It will check if self.logger is an array. If it is, it’ll loop through it and log to every logger. If it’s not, it’ll just log once.

output

Parameters:

  • message (String)

    the message you want to log

  • color (Integer) (defaults to: nil)

    an optional color code to use in the terminal



37
38
39
40
41
42
43
44
45
# File 'lib/navvy/log.rb', line 37

def self.info(message, color = nil)
  if logger.is_a? Array
    logger.each do |logger|
      write(logger, message, color)
    end
  else
    write(logger, message, color)
  end
end

.write(logger, message, color = nil) ⇒ Object

Actually write the log to the logger. It’ll check self.logger and use that to define a logger

output

Parameters:

  • logger (Symbol)

    the logger you want to use

  • message (String)

    the message you want to log

  • color (Integer) (defaults to: nil)

    an optional color code to use in the terminal



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/navvy/log.rb', line 56

def self.write(logger, message, color = nil)
  puts "\e[#{color}m#{message}\e[0m" unless quiet
  case logger
  when :justlogging
    raise(
      LoggerNotFound,
      'JustLogging could not be found. No logs were created.'
    ) unless defined? Justlogging.log
    Justlogging.log(message)  
  when :rails
    raise(
      LoggerNotFound,
      'Rails.logger could not be found. No logs were created.'
    ) unless defined? Rails.logger.info
    Rails.logger.info(message)
  end
end