dvInstallApplicationLogging function

DVLogInstallation? dvInstallApplicationLogging({
  1. required String appId,
  2. required String release,
  3. required DVLogConfig config,
  4. Uri api(
    1. String path
    )?,
  5. bool evenUnderTest = false,
})

Installs DV.log's destinations for the application appId at release from dartvel.logging: the platform log, the device's capped log file, the crash reporter's breadcrumbs and, when declared, shipping to the backend api reaches. What the generated runtime calls at startup.

Null under flutter test unless evenUnderTest. Never throws: a log that cannot be set up is not a reason for the application not to start.

Implementation

DVLogInstallation? dvInstallApplicationLogging({
  required String appId,
  required String release,
  required DVLogConfig config,
  Uri Function(String path)? api,
  bool evenUnderTest = false,
}) {
  if (_installed != null) return _installed;
  if (!evenUnderTest && platform.dvLogHostedByTestRunner()) return null;
  try {
    DVLogFile? file;
    if (config.file) {
      try {
        file = platform.dvDefaultLogFile(appId, config);
      } on Object {
        file = null;
      }
      if (file != null) core.DV.ObservabilityAndLogging.useLogFile(file);
    }
    final DVLogSink? native = config.native ? dvNativeLogSink(appId: appId) : null;
    DVLogShipper? shipper;
    if (config.ship && api != null) {
      shipper = DVLogShipper.toBackend(
        endpoint: () => api(DVLogIngest.path),
        installId: crash_platform.dvInstallId(appId),
        release: release,
        platform: platform.dvLogPlatformName(),
        level: config.shipLevel,
        batch: config.shipBatch,
      );
    }
    core.DV.ObservabilityAndLogging.useLogging(
      sinks: <DVLogSink>[?native, ?shipper, _CrashBreadcrumbSink()],
      level: config.level,
    );
    return _installed =
        DVLogInstallation._(file: file, native: native, shipper: shipper);
  } on Object {
    return null;
  }
}