Skip to content

Commit 7855cd0

Browse files
MB-47505 Add try catch block around io_lib:format/3
To get a balance between performance gains acheived via log truncation and bugs in io_lib:format/3 ... adding a try catch block and defaulting to printing the entire term if io_lib:format/3 fails for any reason. I have also added ~n at the end of each line in the generated code. dynamic_compile:load_from_string is very finicky (atleast for me) and the error messages are hard to decipher since the compiler cann't point exactly where in the "loooong string" did the error occur, due to the obvious lack of line numbers you would otherwise generally find in a source file. Change-Id: I1f6a54c3f3457a651c38d46923e133d306a908b5 Reviewed-on: http://review.couchbase.org/c/ns_server/+/159449 Well-Formed: Build Bot <[email protected]> Tested-by: Build Bot <[email protected]> Tested-by: <[email protected]> Reviewed-by: Meni Hillel <[email protected]>
1 parent fafef40 commit 7855cd0

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

deps/ale/src/ale_codegen.erl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,21 @@ generic_loglevel(LoggerName, LogLevel, Formatter, Preformatted, Raw) ->
126126
true ->
127127
io_lib:format(
128128
"Info = ale_utils:assemble_info(~s, ~p, M, F, L, Data),"
129-
"UserMsg = case Args =/= [] of"
130-
" true ->"
131-
" CharsLimit = proplists:get_value(chars_limit, Opts, ~B),"
132-
" io_lib:format(Fmt, Args, [{chars_limit, CharsLimit}]);"
133-
" false -> Fmt"
134-
" end,",
129+
"UserMsg = case Args =/= [] of~n"
130+
" true ->~n"
131+
" CharsLimit = proplists:get_value(chars_limit, Opts, ~B),~n"
132+
" %% io_lib:format/3 has had bugs and therefore~n"
133+
" %% to avoid any logging errors, the following~n"
134+
" %% try catch block has been added.~n"
135+
" %% https://github.com/erlang/otp/issues/5053~n"
136+
" try~n"
137+
" io_lib:format(Fmt, Args, [{chars_limit, CharsLimit}])~n"
138+
" catch~n"
139+
" _:_ ->~n"
140+
" io_lib:format(Fmt, Args)~n"
141+
" end;~n"
142+
" false -> Fmt~n"
143+
" end,~n",
135144
[LoggerName, LogLevel, ?CHARS_LIMIT_DEFAULT]);
136145
false ->
137146
""

0 commit comments

Comments
 (0)