The value to report
Optionallength: numberThe maximum length in code points of the reported string content, counted before escaping; longer
content is clipped, with the last retained code point replaced by an ellipsis; 0 or a negative value disables
clipping; ignored for values other than strings; defaults to 0
The formatted number, quoted and escaped string literal, error message, function name with an empty
argument list, or string representation of value
Formats a value as a readable report.
Reports numbers with grouped digits, strings as quoted literals with their invisible characters surfaced as escapes, errors through their message, functions through their name, and every other value through its string representation.
Numbers
Numbers are formatted with the digit grouping of the
en-USlocale, whatever the ambient locale, so that reports of the same value are comparable across systems.Strings
String content is delimited by quotation marks, so leading and trailing whitespace is bounded and its extent is unambiguous, and is escaped so that nothing it carries can hide from the log or corrupt it: the quotation mark and the reverse solidus, which would otherwise close or escape the literal, and every character with no visible glyph of its own, that is control characters, line and paragraph separators, space separators other than the plain space, format characters, default ignorable code points whatever their general category, unassigned and private use code points, the blank braille pattern and isolated surrogates. Escapes take the two-character JSON form where one is defined (
\",\\,\b,\f,\n,\r,\t) and the\uXXXX/\UXXXXXXXXnumeric form otherwise.The zero width joiner, the variation selectors and the combining marks are reported as they are: none of them renders on its own, but each alters a visible neighbouring glyph, so escaping them would break composed emoji, ideographic variants and the scripts that require marks, without revealing anything the rendered text doesn't already show. A leading mark attaches to the opening quotation mark of the report.
Errors
Errors are reported through their message, without the class name their string representation would prefix it with: the level and the context of the log entry already state that a failure is being reported. Messages are composed by the throwing code rather than carried in from the outside, so they are reported as they are, neither delimited, escaped nor clipped: report the offending values separately where their extent or their invisible content matters.
Functions
Functions are reported through their name followed by an empty argument list, classes and other callable values included, rather than through the source text their string representation would expose: the name identifies the function in the code, while its body would bury the log entry under content that belongs to the source. Names are code-defined, so they are reported as they are, neither escaped nor clipped. Anonymous functions, whose name is empty because no declaration, binding or property definition supplied one, take the
functionkeyword in place of a name and are reported asfunction().Other Values
Every other value is reported through its string representation, error-like values that are not
Errorinstances included, whatever message-like properties they may carry.