Class: Slugforge::Logger

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

Instance Method Summary collapse

Constructor Details

#initialize(thor_shell, log_level = :info) ⇒ Logger

Returns a new instance of Logger.



3
4
5
6
# File 'lib/slugforge/models/logger.rb', line 3

def initialize(thor_shell, log_level = :info)
  @thor_shell = thor_shell
  @log_level  = log_level
end

Instance Method Details

#log(message = "", opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/slugforge/models/logger.rb', line 8

def log(message="", opts={})
  return if @log_level != :verbose && opts[:log_level] == :verbose
  if opts[:status]
    say_status opts[:status], message, opts[:color]
  else
    if opts[:force_new_line]
      say message, opts[:color], true
    else
      say message, opts[:color]
    end
  end
end

#say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\z/)) ⇒ Object



21
22
23
24
# File 'lib/slugforge/models/logger.rb', line 21

def say(message="", color=nil, force_new_line=(message.to_s !~ /( |\t)\z/))
  return if [:quiet, :json].include?(@log_level)
  @thor_shell.say message, color, force_new_line
end

#say_json(message) ⇒ Object



31
32
33
34
# File 'lib/slugforge/models/logger.rb', line 31

def say_json(message)
  return unless @log_level == :json
  @thor_shell.say message.to_json
end

#say_status(status, message, log_status = true) ⇒ Object



26
27
28
29
# File 'lib/slugforge/models/logger.rb', line 26

def say_status(status, message, log_status=true)
  return if [:quiet, :json].include?(@log_level)
  @thor_shell.say_status status, message, log_status
end