fix: truncate large payload

This commit is contained in:
zhongwencool 2023-08-10 09:35:12 +08:00
parent d5fe891961
commit 5a4dd3a5e5
3 changed files with 9 additions and 8 deletions

View File

@ -620,13 +620,13 @@ format_payload(Payload, hex) when ?MAX_PAYLOAD_FORMAT_LIMIT(Payload) ->
["Payload(hex)=", binary:encode_hex(Payload)]; ["Payload(hex)=", binary:encode_hex(Payload)];
format_payload(_, hidden) -> format_payload(_, hidden) ->
"Payload=******"; "Payload=******";
format_payload(<<Part:?MAX_PAYLOAD_FORMAT_SIZE, _/binary>> = Payload, _) -> format_payload(<<Part:100, _/binary>> = Payload, _) ->
[ [
"Payload=", "Payload=",
Part, Part,
"...The ", "... The ",
integer_to_list(byte_size(Payload) - ?MAX_PAYLOAD_FORMAT_SIZE), integer_to_list(byte_size(Payload) - 100),
"bytes of this log are truncated" " bytes of this log are truncated"
]. ].
i(true) -> 1; i(true) -> 1;

View File

@ -76,12 +76,12 @@ format_payload(_, hidden) ->
format_payload(Payload, text) when ?MAX_PAYLOAD_FORMAT_LIMIT(Payload) -> format_payload(Payload, text) when ?MAX_PAYLOAD_FORMAT_LIMIT(Payload) ->
unicode:characters_to_list(Payload); unicode:characters_to_list(Payload);
format_payload(Payload, hex) when ?MAX_PAYLOAD_FORMAT_LIMIT(Payload) -> binary:encode_hex(Payload); format_payload(Payload, hex) when ?MAX_PAYLOAD_FORMAT_LIMIT(Payload) -> binary:encode_hex(Payload);
format_payload(<<Part:?MAX_PAYLOAD_FORMAT_SIZE, _/binary>> = Payload, _) -> format_payload(<<Part:100, _/binary>> = Payload, _) ->
[ [
Part, Part,
"...The ", "... The ",
integer_to_list(byte_size(Payload) - ?MAX_PAYLOAD_FORMAT_SIZE), integer_to_list(byte_size(Payload) - 100),
"bytes of this log are truncated" " bytes of this log are truncated"
]. ].
to_iolist(Atom) when is_atom(Atom) -> atom_to_list(Atom); to_iolist(Atom) when is_atom(Atom) -> atom_to_list(Atom);

View File

@ -0,0 +1 @@
Prevent client disconnected when sending large payloads with debug/trace logging is enabled.