Multi Agent

In the case you may want to have multiple loggers that serve different purposes, Birch can operate with multiple agents.

An example of multi agent is if you wanted the following:

  • An agent strictly for analytics that drains to Elasticsearch.
  • An agent for general purpose logging that drains to Logtail.

Each agent can have independent configurations and environments.

Getting Started

Instead of using the Birch class, you will now use the Agent class.

Each agent must have a unique directory.

Kotlin

import com.gruffins.birch.Agent

class MyApp: Application() {

  lateinit var analytics: Agent
  lateinit var logger: Agent

  override fun onCreate() {
    super.onCreate()

    analytics = Agent("analytics").also {
      it.init(this, "ANALYTICS_API_KEY", "ANALYTICS_PUBLIC_ENCRYPTION_KEY")
      it.identifier = "your_user_id"
    }

    logger = Agent("logger").also {
      it.init(this, "LOGGER_API_KEY", "LOGGER_PUBLIC_ENCRYPTION_KEY")
      it.identifer = "your_user_id"
    }

    analytics.d { "app_started" }
    logger.d { "Application started" }
  }
}

Swift

import Birch

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var analytics: Agent!
  var logger: Agent!

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
    analytics = Agent(directory: "analytics")
    analytics.initialize("ANALYTICS_API_KEY", publicKey: "ANALYTICS_PUBLIC_ENCRYPTION_KEY")
    analytics.identifier = "your_user_id"

    logger = Agent(directory: "logger")
    logger.initialize("LOGGER_API_KEY", publicKey: "LOGGER_PUBLIC_ENCRYPTION_KEY")
    logger.identifier = "your_user_id"

    return true
  }
}