Skip to content

Commit

Permalink
🐛 Refactored logging to do something useful again
Browse files Browse the repository at this point in the history
Values and surrounding code had evovled such that tool executor results logging was doing very little.
  • Loading branch information
mkarlesky committed May 14, 2024
1 parent 85869b4 commit f483413
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 55 deletions.
21 changes: 3 additions & 18 deletions lib/ceedling/tool_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def exec(command, args=[])
shell_result[:output].gsub!(/\033\[\d\dm/,'')
end

@tool_executor_helper.print_happy_results( command_line, shell_result, options[:boom] )
@tool_executor_helper.print_error_results( command_line, shell_result, options[:boom] )
@tool_executor_helper.log_results( command_line, shell_result )

# Go boom if exit code is not 0 and we want to debug (in some cases we don't want a non-0 exit code to raise)
# Go boom if exit code is not 0 and that code means a fatal error
# (Sometimes we don't want a non-0 exit code to cause an exception as the exit code may not mean a build-ending failure)
if ((shell_result[:exit_code] != 0) and options[:boom])
raise ShellExecutionException.new(
shell_result: shell_result,
Expand All @@ -87,21 +87,6 @@ def exec(command, args=[])
return shell_result
end


def segfault?(shell_result)
return true if (shell_result[:output] =~ /\s*Segmentation\sfault.*/i)

# Assuming that all platforms other than Windows are Unix-like (including Cygwin)
# Unix Signal 11 ==> SIGSEGV
return true if (shell_result[:status].termsig == 11) and !@system_wrapper.windows?

# TODO: Confirm this with PR #856 author (unclear where exit status 3 comes from)
# return true if (shell_result[:status].exitstatus == 3)

return false
end


private #############################


Expand Down
79 changes: 42 additions & 37 deletions lib/ceedling/tool_executor_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Helper functions for the tool executor
class ToolExecutorHelper

constructor :loginator, :system_utils, :system_wrapper
constructor :loginator, :system_utils, :system_wrapper, :verbosinator

##
# Returns the stderr redirection based on the config and logging.
Expand Down Expand Up @@ -74,48 +74,53 @@ def stderr_redirect_cmdline_append(tool_config)
end

##
# Outputs success results if command succeeded and we have verbosity cranked up.
# Logs tool execution results
# ==== Attributes
#
# * _command_str_: The command ran.
# * _shell_results_: The outputs of the command including exit code and
# output.
# * _boom_: A boolean representing if a non zero result is erroneous.
# * _shell_results_: The outputs of the command including exit code and output.
#
def print_happy_results(command_str, shell_result, boom=true)
if ((shell_result[:exit_code] == 0) or ((shell_result[:exit_code] != 0) and not boom))
output = "> Shell executed command:\n"
output += "'#{command_str}'\n"
output += "> Produced output:\n" if (not shell_result[:output].empty?)
output += "#{shell_result[:output].strip}\n" if (not shell_result[:output].empty?)
output += "> And exited with status: [#{shell_result[:exit_code]}].\n" if (shell_result[:exit_code] != 0)
output += "\n"

@loginator.log(output, Verbosity::OBNOXIOUS)
def log_results(command_str, shell_result)
# No logging unless we're at least at Obnoxious
return if !@verbosinator.should_output?( Verbosity::OBNOXIOUS )

output = "> Shell executed command:\n"
output += "'#{command_str}'\n"

# Detailed debug logging
if @verbosinator.should_output?( Verbosity::DEBUG )
output += "> Produced output: "
output += shell_result[:output].empty? ? "<empty>\n" : "\n#{shell_result[:output].chomp("\n")}\n"

output += "> With $stdout: "
output += shell_result[:stdout].empty? ? "<empty>\n" : "\n#{shell_result[:stdout].to_s.chomp("\n")}\n"

output += "> With $stderr: "
output += shell_result[:stderr].empty? ? "<empty>\n" : "\n#{shell_result[:stderr].to_s.chomp("\n")}\n"

output += "> And terminated with status: #{shell_result[:status]}\n"

@loginator.log( '', Verbosity::DEBUG )
@loginator.log( output, Verbosity::DEBUG )
@loginator.log( '', Verbosity::DEBUG )

return # Bail out
end
end

##
# Outputs failures results if command failed and we have verbosity set to minimum error level.
# ==== Attributes
#
# * _command_str_: The command ran.
# * _shell_results_: The outputs of the command including exit code and
# output.
# * _boom_: A boolean representing if a non zero result is erroneous.
#
def print_error_results(command_str, shell_result, boom=true)
if ((shell_result[:exit_code] != 0) and boom)
output = "Shell command failed.\n"
output += "> Shell executed command:\n"
output += "'#{command_str}'\n"
output += "> Produced output:\n" if (not shell_result[:output].empty?)
output += "#{shell_result[:output].strip}\n" if (not shell_result[:output].empty?)
output += "> And exited with status: [#{shell_result[:exit_code]}].\n" if (shell_result[:exit_code] != nil)
output += "> And then likely crashed.\n" if (shell_result[:exit_code] == nil)
output += "\n"

@loginator.log( output, Verbosity::ERRORS )
# Slightly less verbose obnoxious logging
if !shell_result[:output].empty?
output += "> Produced output:\n"
output += "#{shell_result[:output].chomp("\n")}\n"
end

if !shell_result[:exit_code].nil?
output += "> And terminated with exit code: [#{shell_result[:exit_code]}]\n"
else
output += "> And exited prematurely\n"
end

@loginator.log( '', Verbosity::OBNOXIOUS )
@loginator.log( output, Verbosity::OBNOXIOUS )
@loginator.log( '', Verbosity::OBNOXIOUS )
end
end

0 comments on commit f483413

Please sign in to comment.