Module: AppArchetype::Logger

Included in:
Renderer
Defined in:
lib/app_archetype/logger.rb

Overview

CLI Logging methods

Instance Method Summary collapse

Instance Method Details

#logger(out = STDOUT) ⇒ ::Logger

Creates logger for printing messages

Sets the formatter to output only the provided message to the specified IO



14
15
16
17
18
19
20
21
# File 'lib/app_archetype/logger.rb', line 14

def logger(out = STDOUT)
  @logger ||= ::Logger.new(out)
  @logger.formatter = proc do |_sev, _time, _prog, msg|
    "#{msg}\n"
  end

  @logger
end

Prints error to STDERR

For indicating fatal message to user



52
53
54
# File 'lib/app_archetype/logger.rb', line 52

def print_error(message)
  logger(STDERR).error(message)
end

Prints command line message to STDOUT

For use when printing info messages for a user to STDOUT



30
31
32
# File 'lib/app_archetype/logger.rb', line 30

def print_message(message)
  logger.info(message)
end

Prints a message and then exits with given status code

This will terminate the program with the given status code



64
65
66
67
# File 'lib/app_archetype/logger.rb', line 64

def print_message_and_exit(message, exit_code = 1)
  print_message(message)
  exit(exit_code)
end

Prints warning to STDOUT

For use when printing warn messages to STDOUT



41
42
43
# File 'lib/app_archetype/logger.rb', line 41

def print_warning(message)
  logger.warn(message)
end