Skip to content

Commit

Permalink
Truncating log messages when they are too large
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Cheal committed Nov 21, 2017
1 parent bc37126 commit ad4fb78
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/gems/pending/util/vmdb-logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ class Formatter < Logger::Formatter
FORMAT = "[----] %s, [%s#%d:%x] %5s -- %s: %s\n"

def call(severity, time, progname, msg)
msg = prefix_task_id(msg2str(msg))
max_log_line_length = 1.megabyte

msg = prefix_task_id(msg2str(msg)).truncate(max_log_line_length)
FORMAT % [severity[0..0], format_datetime(time), $PROCESS_ID, Thread.current.object_id, severity, progname, msg]
end

Expand Down
6 changes: 6 additions & 0 deletions spec/util/vmdb-logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
expect(VMDBLogger.contents("mylog.log")).to eq("")
end

context "long messages" do
it "truncates long messages when max_message_size is set" do
# TODO Add test body!
end
end

context "with evm log snippet with invalid utf8 byte sequence data" do
before(:each) do
@log = File.expand_path(File.join(File.dirname(__FILE__), "data/redundant_utf8_byte_sequence.log"))
Expand Down

0 comments on commit ad4fb78

Please sign in to comment.