objectToString static method
String
objectToString(
- Object? obj, {
- LogTheme theme = LogTheme.noColors,
- int depth = 0,
- LoggableConfig config = const LoggableConfig(),
Converts an object to a string using the theme and the
config.
Implementation
static String objectToString(
Object? obj, {
LogTheme theme = LogTheme.noColors,
int depth = 0,
LoggableConfig config = const LoggableConfig(),
}) {
// LoggableWrapper is transparent packaging for render parameters, not
// a value in its own right. It is unwrapped before the root check:
// otherwise the sanitizer would see the wrapper and its contents as two
// different roots (the wrapper object, and then the data inside it
// again).
if (obj is LoggableWrapper) {
return objectToString(
obj.data,
theme: theme,
depth: depth,
config: obj.config.merge(config),
);
}
// The root offer lives in the shared helper: the multi-data renderers
// that do not pass through this walker call the same one.
if (sanitizeRootToString(obj, theme: theme, depth: depth, config: config)
case final rendered?) {
return rendered.text;
}
// A root the rule left alone renders under the guard too, not only a
// replacement. Otherwise the stack would stay empty for the duration of
// the root render, and `toString()` of any [Loggable] the render
// reaches directly (a [Map] key, interpolation inside someone else's
// `toString`) would make an offer of ITS OWN — the same root would be
// offered to the rule a second time.
if (_sanitizing && _sanitizeSegments.isEmpty) {
return _withSegment(
_rootGuardSegment,
() => _visitToString(obj, theme: theme, depth: depth, config: config),
);
}
return _visitToString(obj, theme: theme, depth: depth, config: config);
}