View Source trunc_io (util v1.1.5)
Module to print out terms for logging. Limits by length rather than depth.
The resulting string may be slightly larger than the limit; the intention is to provide predictable CPU and memory consumption for formatting terms, not produce precise string lengths.
Typical use:
trunc_io:print(Term, 500).
Source license: Erlang Public License. Original author: Matthias Lang, matthias@corelatus.seLink to this section Summary
Functions
Returns an flattened list containing the ASCII representation of the given term.
Returns {List, Length}
Same as print, but never crashes.
Link to this section Functions
-spec fprint(term(), pos_integer()) -> string().
-spec perf1() -> {non_neg_integer(), non_neg_integer()}.
-spec perf() -> ok.
-spec perf(atom(), atom(), integer()) -> done.
-spec print(term(), pos_integer()) -> {iolist(), pos_integer()}.
-spec safe(term(), pos_integer()) -> {string(), pos_integer()} | {string()}.
Same as print, but never crashes.
This is a tradeoff. Print might conceivably crash if it's asked to print something it doesn't understand, for example some new data type in a future version of Erlang. If print crashes, we fall back to io_lib to format the term, but then the formatting is depth-limited instead of length limited, so you might run out memory printing it. Out of the frying pan and into the fire.-spec test() -> ok.
-spec test(atom(), atom()) -> ok.