Skip to content

Commit

Permalink
🔀 Resolved merge conflict
Browse files Browse the repository at this point in the history
Ported streaminator change for an array argument (in place of usual string) into new and improved loginator.
  • Loading branch information
mkarlesky committed May 7, 2024
1 parent 1d4e296 commit 8a9fa7c
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/ceedling/loginator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,38 +63,44 @@ def set_logfile( log_filepath )
# - Any problematic console characters in a message are replaced with
# simpler variants

def log(string, verbosity=Verbosity::NORMAL, label=LogLabels::AUTO, stream=nil)
def log(message, verbosity=Verbosity::NORMAL, label=LogLabels::AUTO, stream=nil)
# Flatten if needed
message = message.flatten.join("\n") if (message.class == Array)

# Call out() with string contatenated with "\n" (unless it aready ends with a newline)
string += "\n" unless string.end_with?( "\n" )
out( string, verbosity, label, stream )
message += "\n" unless message.end_with?( "\n" )
out( message, verbosity, label, stream )
end


def out(string, verbosity=Verbosity::NORMAL, label=LogLabels::AUTO, stream=nil)
def out(message, verbosity=Verbosity::NORMAL, label=LogLabels::AUTO, stream=nil)
# Choose appropriate console stream
stream = get_stream( verbosity, stream )

# Flatten if needed
message = message.flatten.join("\n") if (message.class == Array)

# Write to log as though Verbosity::DEBUG (no filtering at all) but without fun characters
if @project_logging
file_str = string.dup() # Copy for safe inline modifications
file_msg = message.dup() # Copy for safe inline modifications

# Add labels
file_str = format( file_str, verbosity, label, false )
file_msg = format( file_msg, verbosity, label, false )

# Note: In practice, file-based logging only works with trailing newlines (i.e. `log()` calls)
# `out()` calls will be a little ugly in the log file, but these are typically only
# used for console logging anyhow.
logfile( sanitize( file_str, false ), extract_stream_name( stream ) )
logfile( sanitize( file_msg, false ), extract_stream_name( stream ) )
end

# Only output to console when message reaches current verbosity level
return if !(@verbosinator.should_output?( verbosity ))

# Add labels and fun characters
console_str = format( string, verbosity, label, @decorators )
console_msg = format( message, verbosity, label, @decorators )

# Write to output stream after optionally removing any problematic characters
stream.print( sanitize( console_str, @decorators ) )
stream.print( sanitize( console_msg, @decorators ) )
end


Expand Down

0 comments on commit 8a9fa7c

Please sign in to comment.