trunc_io (util v1.3.5)

View Source

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.se

Summary

Functions

Returns an flattened list containing the ASCII representation of the given term.

Returns {List, Length}

Same as print, but never crashes.

Functions

fprint(T, Max)

-spec fprint(term(), pos_integer()) -> string().

Returns an flattened list containing the ASCII representation of the given term.

perf1()

-spec perf1() -> {non_neg_integer(), non_neg_integer()}.

perf()

-spec perf() -> ok.

perf/3

-spec perf(atom(), atom(), integer()) -> done.

print/2

-spec print(term(), pos_integer()) -> {iolist(), pos_integer()}.

Returns {List, Length}

safe(What, Len)

-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.

test()

-spec test() -> ok.

test(Mod, Func)

-spec test(atom(), atom()) -> ok.