Class: Tomo::Logger

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Colors
Defined in:
lib/tomo/logger.rb,
lib/tomo/logger/tagged_io.rb

Defined Under Namespace

Classes: TaggedIO

Instance Method Summary collapse

Methods included from Colors

enabled?

Constructor Details

#initialize(stdout: $stdout, stderr: $stderr) ⇒ Logger

Returns a new instance of Logger.



12
13
14
15
# File 'lib/tomo/logger.rb', line 12

def initialize(stdout: $stdout, stderr: $stderr)
  @stdout = TaggedIO.new(stdout)
  @stderr = TaggedIO.new(stderr)
end

Instance Method Details

#connect(host) ⇒ Object



39
40
41
42
43
# File 'lib/tomo/logger.rb', line 39

def connect(host)
  return if Tomo.quiet?

  puts gray("→ Connecting to #{host}")
end

#debug(message) ⇒ Object



65
66
67
68
69
# File 'lib/tomo/logger.rb', line 65

def debug(message)
  return unless Tomo.debug?

  stderr.puts gray("DEBUG: #{message}")
end

#error(message) ⇒ Object



57
58
59
# File 'lib/tomo/logger.rb', line 57

def error(message)
  stderr.puts indent("\n" + red("ERROR: ") + message.strip + "\n\n")
end

#info(message) ⇒ Object



51
52
53
54
55
# File 'lib/tomo/logger.rb', line 51

def info(message)
  return if Tomo.quiet?

  puts message
end

#script_end(script, result) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/tomo/logger.rb', line 30

def script_end(script, result)
  return if Tomo.quiet?
  return unless result.failure?
  return unless script.silent?
  return unless script.raise_on_error?

  puts result.output
end

#script_output(script, output) ⇒ Object



24
25
26
27
28
# File 'lib/tomo/logger.rb', line 24

def script_output(script, output)
  return if script.silent?

  puts output
end

#script_start(script) ⇒ Object



17
18
19
20
21
22
# File 'lib/tomo/logger.rb', line 17

def script_start(script)
  return if Tomo.quiet?
  return unless script.echo?

  puts yellow(script.echo_string)
end

#task_start(task) ⇒ Object



45
46
47
48
49
# File 'lib/tomo/logger.rb', line 45

def task_start(task)
  return if Tomo.quiet?

  puts blue("#{task}")
end

#warn(message) ⇒ Object



61
62
63
# File 'lib/tomo/logger.rb', line 61

def warn(message)
  stderr.puts red("WARNING: ") + message
end