Skip to content

Commit

Permalink
Handle non-UTF-8 in LogFormatter (#73)
Browse files Browse the repository at this point in the history
The LogFormatter previously raised "invalid byte sequence in UTF-8
(ArgumentError)" for any non-UTF-8 logging due to strip not supporting
non-UTF-8 strings.
  • Loading branch information
robinkar authored Feb 5, 2025
1 parent 5df4069 commit 9cb39d8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ood_appkit/log_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class LogFormatter
def call(severity, timestamp, progname, msg)
severity_d = severity ? severity[0,5].rjust(5).upcase : "UNKNO"
timestamp_d = timestamp ? timestamp.localtime : Time.now.localtime
msg_d = (String === msg ? msg.strip.inspect : msg.inspect)
msg_d = (String === msg ? msg.encode("UTF-8", :invalid => :replace, :undef => :replace).strip.inspect : msg.inspect)

"[#{timestamp_d} #{progname}] #{severity_d} #{msg_d}\n"
end
Expand Down

0 comments on commit 9cb39d8

Please sign in to comment.