Class: Heroku::Helpers::LogDisplayer
- Inherits:
-
Object
- Object
- Heroku::Helpers::LogDisplayer
- Includes:
- Heroku::Helpers
- Defined in:
- lib/heroku/helpers/log_displayer.rb
Constant Summary collapse
- COLORS =
%w( cyan yellow green magenta red )
- COLOR_CODES =
{ "red" => 31, "green" => 32, "yellow" => 33, "magenta" => 35, "cyan" => 36, }
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#heroku ⇒ Object
readonly
Returns the value of attribute heroku.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #colorize(chunk) ⇒ Object
- #display_logs ⇒ Object
-
#initialize(heroku, app, opts) ⇒ LogDisplayer
constructor
A new instance of LogDisplayer.
- #parse_log(log) ⇒ Object
Methods included from Heroku::Helpers
#action, #ask, #confirm, #confirm_billing, #confirm_command, #create_git_remote, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #error, error_with_failure, error_with_failure=, extended, extended_into, #fail, #format_bytes, #format_date, #format_error, #format_with_bang, #get_terminal_environment, #git, #has_git?, #home_directory, #host_name, #hprint, #hputs, included, included_into, #json_decode, #json_encode, #launchy, #line_formatter, #longest, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #time_ago, #truncate, #with_tty
Constructor Details
#initialize(heroku, app, opts) ⇒ LogDisplayer
Returns a new instance of LogDisplayer.
10 11 12 |
# File 'lib/heroku/helpers/log_displayer.rb', line 10 def initialize(heroku, app, opts) @heroku, @app, @opts = heroku, app, opts end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
8 9 10 |
# File 'lib/heroku/helpers/log_displayer.rb', line 8 def app @app end |
#heroku ⇒ Object (readonly)
Returns the value of attribute heroku.
8 9 10 |
# File 'lib/heroku/helpers/log_displayer.rb', line 8 def heroku @heroku end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
8 9 10 |
# File 'lib/heroku/helpers/log_displayer.rb', line 8 def opts @opts end |
Instance Method Details
#colorize(chunk) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/heroku/helpers/log_displayer.rb', line 45 def colorize(chunk) lines = [] chunk.split("\n").map do |line| if parsed_line = parse_log(line) header, identifier, body = parsed_line @assigned_colors[identifier] ||= COLORS[@assigned_colors.size % COLORS.size] lines << [ "\e[#{COLOR_CODES[@assigned_colors[identifier]]}m", header, "\e[0m", body, ].join("") elsif not line.empty? lines << line end end lines.join("\n") end |
#display_logs ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/heroku/helpers/log_displayer.rb', line 14 def display_logs @assigned_colors = {} @line_start = true @token = nil heroku.read_logs(app, opts) do |chunk| unless chunk.empty? if STDOUT.isatty && ENV.has_key?("TERM") display(colorize(chunk)) else display(chunk) end end end rescue Errno::EPIPE rescue Interrupt => interrupt if STDOUT.isatty && ENV.has_key?("TERM") display("\e[0m") end raise(interrupt) end |
#parse_log(log) ⇒ Object
64 65 66 67 |
# File 'lib/heroku/helpers/log_displayer.rb', line 64 def parse_log(log) return unless parsed = log.match(/^(.*?\[(\w+)([\d\.]+)?\]:)(.*)?$/) [1, 2, 4].map { |i| parsed[i] } end |