Class: Docker::Template::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/docker/template/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(builder = nil) ⇒ Logger

Returns a new instance of Logger.



10
11
12
13
14
# File 'lib/docker/template/logger.rb', line 10

def initialize(builder = nil)
  @lines = { 0 => 0 }
  @builder = \
    builder
end

Instance Method Details

#api(part, *_) ⇒ Object


A more complex streamer designed for the actual output of the Docker.




45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/docker/template/logger.rb', line 45

def api(part, *_)
  stream = JSON.parse(part)
  retried ||= false

  return progress_bar(stream) if stream.any_key?("progress", "progressDetail")
  return output(stream["status"] || stream["stream"]) if stream.any_key?("status", "stream")
  return progress_error(stream) if stream.any_key?("errorDetail", "error")

  warn Simple::Ansi.red("Unhandled Stream.")
  $stdout.puts(
    part
  )

# Addresses a Docker 1.9 bug.
rescue JSON::ParserError => e
  if !retried
    retried = true
    part = "#{part}\" }"
    retry
  else
    raise e
  end
end

#incrementObject




18
19
20
21
22
# File 'lib/docker/template/logger.rb', line 18

def increment
  @lines.update({
    @lines.size => @lines.size
  })
end

#output(msg) ⇒ Object




71
72
73
74
75
76
# File 'lib/docker/template/logger.rb', line 71

def output(msg)
  unless filter_matches?(msg)
    $stdout.puts msg
    increment
  end
end

#progress_error(stream) ⇒ Object




80
81
82
83
84
# File 'lib/docker/template/logger.rb', line 80

def progress_error(stream)
  abort Object::Simple::Ansi.red(
    stream["errorDetail"]["message"]
  )
end

#simple(type, str) ⇒ Object


A simple logger that accepts a multi-type stream.




37
38
39
# File 'lib/docker/template/logger.rb', line 37

def simple(type, str)
  type == :stderr ? $stderr.print(str) : $stdout.print(str)
end

#tty(stream) ⇒ Object


A simple TTY stream that just prints out the data that it is given. This is the logger that most will use for most of their building.




29
30
31
# File 'lib/docker/template/logger.rb', line 29

def tty(stream)
  $stdout.print stream
end