Module: CodeownerValidator::Logging

Included in:
Command, Tasks::Base
Defined in:
lib/codeowner_validator/common/logging.rb

Overview

Public: Mixin for adding methods needed for logging directly to the stdout

Instance Method Summary collapse

Instance Method Details

#log_command(*messages) ⇒ Object

Public: Displays the command message to the console



29
30
31
32
33
# File 'lib/codeowner_validator/common/logging.rb', line 29

def log_command(*messages)
  messages.flatten.each do |message|
    logger.info Rainbow(message).bright
  end
end

#log_error(*messages) ⇒ Object

Public: Displays an error message to the console



50
51
52
53
54
# File 'lib/codeowner_validator/common/logging.rb', line 50

def log_error(*messages)
  messages.flatten.each do |message|
    logger.error Rainbow(message).red.bold
  end
end

#log_info(*messages) ⇒ Object

Public: Displays an informational message to the console



36
37
38
39
40
# File 'lib/codeowner_validator/common/logging.rb', line 36

def log_info(*messages)
  messages.flatten.each do |message|
    logger.info Rainbow(message).blue.bright
  end
end

#log_stderr(*args) ⇒ Object

Public: Displays the stderr output to the console



57
58
59
60
61
# File 'lib/codeowner_validator/common/logging.rb', line 57

def log_stderr(*args)
  args.each do |message|
    logger.error message
  end
end

#log_verbose(*messages) ⇒ Object

Public: Designation if to show verbose output



20
21
22
23
24
25
26
# File 'lib/codeowner_validator/common/logging.rb', line 20

def log_verbose(*messages)
  return unless verbose?

  messages.flatten.each do |message|
    logger.info Rainbow(message || yield).magenta.bright
  end
end

#log_warn(*messages) ⇒ Object

Public: Displays a warning message to the console



43
44
45
46
47
# File 'lib/codeowner_validator/common/logging.rb', line 43

def log_warn(*messages)
  messages.flatten.each do |message|
    logger.warn Rainbow(message).yellow
  end
end

#loggerObject

Internal: Reader for the logger attribute.

Returns a Logger instance.



12
13
14
15
16
17
# File 'lib/codeowner_validator/common/logging.rb', line 12

def logger
  return @logger if @logger

  # depending of the context, utilize existing rails logger if exists
  @logger = rails_logger || default_logger
end

#program_nameObject

Public: Displays the current program running name



64
65
66
# File 'lib/codeowner_validator/common/logging.rb', line 64

def program_name
  @program_name ||= File.basename($PROGRAM_NAME)
end