Skip to content

Commit

Permalink
Merge pull request #95 from klyonrad/colorize-logmessage
Browse files Browse the repository at this point in the history
add Label to LogMessage and colorize it
  • Loading branch information
mattbrictson authored Apr 11, 2017
2 parents 53ec128 + 3dd45fc commit 3b912fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. This projec

## [Unreleased]

* colorize LogMessage label on WARN level and above ([@klyonrad](https://github.com/klyonrad))
* Your contribution here!

## [1.1.2][] (2017-01-02)
Expand Down
15 changes: 14 additions & 1 deletion lib/airbrussh/console_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,20 @@ def write(obj)
def write_log_message(log_message)
return if debug?(log_message)
print_task_if_changed
print_indented_line(log_message.to_s)
print_indented_line(format_log_message(log_message))
end

def format_log_message(log_message)
case log_message.verbosity
when SSHKit::Logger::WARN
"#{yellow('WARN')} #{log_message}"
when SSHKit::Logger::ERROR
"#{red('ERROR')} #{log_message}"
when SSHKit::Logger::FATAL
"#{red('FATAL')} #{log_message}"
else
log_message.to_s
end
end

# For SSHKit versions up to and including 1.7.1, the stdout and stderr
Expand Down
13 changes: 7 additions & 6 deletions test/airbrussh/formatter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ def test_handles_rake_tasks
" 02 command 2\n",
/ ✔ 02 #{@user_at_localhost} \d.\d+s\n/,
"00:00 special_rake_task_2\n",
" New task starting\n",
" ERROR New task starting\n",
"00:00 special_rake_task_3\n",
" 01 echo command 3\n",
" 01 command 3\n",
/ ✔ 01 #{@user_at_localhost} \d.\d+s\n/,
" 02 echo command 4\n",
" 02 command 4\n",
/ ✔ 02 #{@user_at_localhost} \d.\d+s\n/,
" All done\n"
" WARN All done\n"
)

assert_log_file_lines(
Expand All @@ -268,7 +268,8 @@ def test_handles_rake_tasks
end

def test_log_message_levels
configure do |_airbrussh_config, sshkit_config|
configure do |airbrussh_config, sshkit_config|
airbrussh_config.color = true
sshkit_config.output_verbosity = Logger::DEBUG
end

Expand All @@ -280,9 +281,9 @@ def test_log_message_levels

assert_output_lines(
" Test\n",
" Test\n",
" Test\n",
" Test\n",
" \e[0;31;49mFATAL\e[0m Test\n",
" \e[0;31;49mERROR\e[0m Test\n",
" \e[0;33;49mWARN\e[0m Test\n",
" Test\n"
)

Expand Down

0 comments on commit 3b912fb

Please sign in to comment.