Privacy and console logs
Looking for the previous SDK? See the 6.x log privacy page.
Disabling log collection
Log collection can be turned off with the CaptureLogs option — see
configuration.
Sanitizing logs
7.0 uses a single generic filter interface, EventFilter<T>, for both log
and network events. Its single filter(log, callback) method hands you the
event and a Callback1 to invoke with the result: call callback.run(log) to
keep the (possibly mutated) event, or callback.run(null) to drop it entirely.
The filter method is synchronous.
The event type is LogEvent (package com.bugsee.library.contracts.exchange).
- Java
- Kotlin
Bugsee.setLogEventFilter((log, callback) -> {
String message = log.getMessage();
if (message != null) {
// Strip tokens, redact PII, etc.
log.setMessage(message.replaceAll("token=\\S+", "token=[REDACTED]"));
}
// Pass the mutated event to keep it…
callback.run(log);
// …or call callback.run(null) to drop it entirely:
// callback.run(null);
});
Bugsee.setLogEventFilter { log, callback ->
log.message?.let { message ->
log.message = message.replace(Regex("token=\\S+"), "token=[REDACTED]")
}
// Pass the mutated event to keep it…
callback.run(log)
// …or call callback.run(null) to drop it entirely:
// callback.run(null)
}
setLogFilter aliasBugsee.setLogFilter(EventFilter<LogEvent>) is a deprecated alias for
setLogEventFilter(...). Both resolve to the same registration.
Declaring the filter in the manifest
You can also point Bugsee at a log filter from AndroidManifest.xml, with no
code. Add a com.bugsee.filter.log-event <meta-data> whose value is a class
that implements EventFilter<LogEvent> and has a public no-arg constructor.
The benefit: the filter is in force from the very first captured event, even
under auto-initialization, before any of your own code runs.
<application>
<meta-data android:name="com.bugsee.filter.log-event"
android:value="com.example.MyLogFilter" />
</application>
- Java
- Kotlin
import androidx.annotation.Keep;
import com.bugsee.library.contracts.common.Callback1;
import com.bugsee.library.contracts.exchange.EventFilter;
import com.bugsee.library.contracts.exchange.LogEvent;
@Keep // referenced only by name in the manifest — keep it from R8
public class MyLogFilter implements EventFilter<LogEvent> {
public MyLogFilter() { } // required public no-arg constructor
@Override
public void filter(LogEvent log, Callback1<LogEvent> callback) {
String message = log.getMessage();
if (message != null) {
log.setMessage(message.replaceAll("token=\\S+", "token=[REDACTED]"));
}
callback.run(log); // pass null to drop
}
}
import androidx.annotation.Keep
import com.bugsee.library.contracts.common.Callback1
import com.bugsee.library.contracts.exchange.EventFilter
import com.bugsee.library.contracts.exchange.LogEvent
@Keep // referenced only by name in the manifest — keep it from R8
class MyLogFilter : EventFilter<LogEvent> {
override fun filter(log: LogEvent, callback: Callback1<LogEvent>) {
log.message?.let {
log.message = it.replace(Regex("token=\\S+"), "token=[REDACTED]")
}
callback.run(log) // pass null to drop
}
}
A filter set in code with Bugsee.setLogEventFilter(...) takes precedence over
the manifest one. Because the class is referenced only by name, keep it from R8
— annotate it @Keep or add -keep class com.example.MyLogFilter { <init>(); }.
The same mechanism is available for network events and breadcrumbs.