Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Label to LogMessage and colorize it #95

Merged
merged 2 commits into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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