sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

how to get diagnostic logs objetivec

Open MariaC15 opened this issue 2 years ago • 3 comments

Description

How can I obtain the logs for mild diagnostics? I am creating a plugin for NativeScript. For example:

      new io.sentry.ILogger({
        isEnabled(param0: io.sentry.SentryLevel) {
          that.printf(param0);
          return value;
        },
        log(param0: io.sentry.SentryLevel, param1: java.lang.Throwable, param2: string, param3: androidNative.Array<any>) {
          that.printf(`${param0} - ${param1} - ${param2} - ${param3}`);
        },
      })

from Android. The logs from NativeScript do not directly display Sentry logs.

MariaC15 avatar Aug 06 '23 02:08 MariaC15

Hi @MariaC15, can you please clarify what you are trying to achieve? And does your use case work on Android the way you described it?

kahest avatar Aug 07 '23 12:08 kahest

Hello, I apologize for not explaining more clearly. I'm creating a plugin for NativeScript using the Sentry libraries for Android and iOS. Due to NativeScript's compilation process for Android and iOS, the logs are not displayed. I resolved this issue for Android using the following approach:

set logger(value: boolean) {
  const that = this;
  this.config.setLogger(
    new io.sentry.ILogger({
      isEnabled(param0: io.sentry.SentryLevel) {
        that.printf(param0);
        return value;
      },
      log(param0: io.sentry.SentryLevel, param1: java.lang.Throwable, param2: string, param3: androidNative.Array<any>) {
        that.printf(`${param0} - ${param1} - ${param2} - ${param3}`);
      },
    })
  );
  this.printf('logger');
}

This solution works correctly for Android, but on iOS, the logs are not visible when compiled through NativeScript. They only appear in Xcode when compiled directly from Xcode. Is it possible to use a similar method to the logger in the Swift library?

MariaC15 avatar Aug 07 '23 16:08 MariaC15

Thanks for the explanation! sentry-cocoa currently does not support setting a custom logger, so your use case is currently not supported. We'll discuss if it makes sense to open this up.

kahest avatar Aug 09 '23 07:08 kahest