Base64LogTrimmer class

Collapses base64 blobs out of the logger's output.

Wired in as ApiLogOptions.logPrint — the only hook into what the logger prints. PrettyDioLogger has no notion of a field worth hiding: it wraps every value at maxWidth and emits one line per 78-odd characters, so a record detail carrying ten fingerprints plus two photographs is tens of thousands of console lines, and the request line that caused them is long gone by the time the body finishes.

This sits between the logger and the console and rewrites that stream:

║      "data": iVBORw0KGgoAAAANSUhEUg…
║      …[412903 base64 chars elided]

It filters lines, not fields, because lines are all it is given — the logger has already flattened the map by the time this is called. So the test is a shape test: a run of characters from the base64 alphabet, long enough that it cannot be an id or a status, that also reads like encoded bytes — upper and lower case, and / no denser than one character in ten. The alphabet alone is not enough: it includes /, so a long url path (/api/v1/organizations/12345/departments) matches it, as do hex digests and git SHAs. Those fail the second test, since a path is slash-dense and usually lowercase, and hex is single-case. Anything else passes through byte for byte, which is the point — a detail string, a case number, a request url and a stack trace still read exactly as they did.

Usually you want ApiLogOptions.trimBase64 rather than this class directly:

ApiServices.init(const ApiConfig(
  logging: ApiLogOptions(trimBase64: true),
));

Construct it yourself when the defaults need tuning for your API, or to place it in front of a sink of your own:

ApiServices.init(ApiConfig(
  logging: ApiLogOptions(
    // This API returns 48-character reference codes that must stay
    // readable, so only collapse runs longer than that.
    logPrint: Base64LogTrimmer(sink: myLogger.debug, minRunLength: 60).call,
  ),
));

One instance holds the running count of elided characters, so give each client its own rather than sharing one across several.

Constructors

Base64LogTrimmer({required void sink(Object object), int keptChars = 24, int minRunLength = 40})

Properties

hashCode → int
The hash code for this object.
no setterinherited
keptChars → int
Characters of a blob kept before the ellipsis, enough to tell a PNG from a JPEG from a JWT.
final
minRunLength → int
Shortest run of the base64 alphabet treated as a blob rather than as an id, a hash, or a token the reader might actually want.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sink → void Function(Object object)
Where surviving lines go. Wrap your own sink to keep it in the chain — it receives lines that have already been trimmed.
final

Methods

call(Object object) → void
Pass this to ApiLogOptions.logPrint.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited