Scrubbers

Scrubbing is the process of removing sensitive logging information before it leaves the device. Scrubbing happens on the agent so it stops sensitive data at the source, limiting it's exposure to other services.

Birch will automatically apply an email and a password scrubber to your logs.

Creating a Scrubber

A scrubber simply needs to extend the Scrubber class and override the scrub() function.

scrub() is called for every log message and is responsible for returning a cleansed string.

Kotlin

import com.gruffins.birch.Scrubber

class YourScrubber: Scrubber {
  override fun scrub(input: String): String {
    return input.replace("YOUR_REGEX".toRegex(), "[FILTERED]")
  }
}

Swift

import Birch

class YourScrubber: Scrubber {
  init() {}

  public func scrub(input: String) -> String {
    return input.replacingOccurrences(
      of: "YOUR_REGEX",
      with: "[FILTERED]",
      options: [.regularExpression, .caseInsensitive]
    )
  }
}

React Native

function customScrubber(input: string): string {
  return input.replaceAll(YOUR_REGEX, "[FILTERED]");
}

Register Your Scrubber

Add your scrubber when you initialize the agent.

Kotlin

Birch.init(
  context,
  "API_KEY",
  "PUBLIC_ENCRYPTION_KEY",
  Options().also {
    it.scrubbers = listOf(PasswordScrubber(), EmailScrubber(), YourScrubber())
  }
)

Swift

let options = Options()
options.scrubbers = [PasswordScrubber(), EmailScrubber(), YourScrubber()]

Birch.initialize(
  "API_KEY",
  publicKey: "PUBLIC_KEY",
  options: options
)

React Native

import Birch, { emailScrubber, passwordScrubber } from 'react-native-birch';
import { useEffect } from 'react';

function customScrubber(input: string): string {
  return input.replaceAll(REGEX, "[FILTERED]");
}

export default function App() {
  useEffect(() => {
    Birch.init({
      apiKey: "api_key",
      publicKey: "public_key",
      options: {
        scrubbers: [customScrubber, emailScrubber, passwordScrubber],
      }
    })
  }, []);
  
  return (
    <></>
  )
}