aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHans Bolinder <[email protected]>2017-05-15 14:27:00 +0200
committerHans Bolinder <[email protected]>2017-05-18 15:29:24 +0200
commitf97921c7ea300ddfce3c37735a6373bd85e55da1 (patch)
tree5bfa6aadfb4f43d8a3a5b63a435fa04af5ea99e5 /lib
parentb57e89092409193457aa2ad026c895d5559d428d (diff)
downloadotp-f97921c7ea300ddfce3c37735a6373bd85e55da1.tar.gz
otp-f97921c7ea300ddfce3c37735a6373bd85e55da1.tar.bz2
otp-f97921c7ea300ddfce3c37735a6373bd85e55da1.zip
kernel: Add error_logger:limit_term/1
Calling error_logger:limit_term/1 before sending terms as events to the error_logger can be used for limiting the size of the messages. Doing so will not change the output, but potentially save memory. The Kernel variable error_logger_format_depth is used when limiting the size of terms.
Diffstat (limited to 'lib')
-rw-r--r--lib/kernel/src/error_logger.erl18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/kernel/src/error_logger.erl b/lib/kernel/src/error_logger.erl
index 81f1bf8d97..93a3f4f2e5 100644
--- a/lib/kernel/src/error_logger.erl
+++ b/lib/kernel/src/error_logger.erl
@@ -31,6 +31,8 @@
handle_event/2, handle_call/2, handle_info/2,
terminate/2]).
+-export([limit_term/1]).
+
-define(buffer_size, 10).
%%-----------------------------------------------------------------
@@ -518,3 +520,19 @@ string_p1([H|T]) when is_list(H) ->
end;
string_p1([]) -> true;
string_p1(_) -> false.
+
+-spec limit_term(term()) -> term().
+
+limit_term(Term) ->
+ case get_depth() of
+ unlimited -> Term;
+ D -> io_lib:limit_term(Term, D)
+ end.
+
+get_depth() ->
+ case application:get_env(kernel, error_logger_format_depth) of
+ {ok, Depth} when is_integer(Depth) ->
+ max(10, Depth);
+ undefined ->
+ unlimited
+ end.