BranchMetrics / ios-branch-deep-linking-attribution

The Branch iOS SDK for deep linking and attribution. Branch helps mobile apps grow with deep links / deeplinks that power paid acquisition and re-engagement campaigns, referral programs, content sharing, deep linked emails, smart banners, custom user onboarding, and more.
https://help.branch.io/developers-hub/docs/ios-sdk-overview
MIT License
728 stars 229 forks source link

[SDK-2163] Added new BranchLogger class #1346

Closed nsingh-branch closed 7 months ago

nsingh-branch commented 7 months ago

Reference

SDK-2163 -- Replace BNCLog with a simpler class based solution

Summary

This PR introduces a new logging class, BranchLogger, designed to replace the existing BNCLog utility. The goal is to simplify logging within the SDK by providing a clear, straightforward way to log messages at different levels (Debug, Info, Warning, Error), support conditional logging based on the set log level threshold, and provide clients with a log callback.

This is phase one of this change which is just creating the new class and implementing it in a few places. Once approved, the next phase will remove the existing BNCLog class and replace all of its usage with BranchLogger.

Motivation

The motivation behind this change is to make it easier to log at different levels throughout the SDK and replace the old BNCLog class. Additionally, this change provide clients with new features like enabling logs only above a certain level and the ability to receive logs via a callbacks instead.

Type Of Change

Testing Instructions

  1. Enable logging in the SDK using the existing [[Branch getInstance] enableLogging] or the new [[Branch getInstance] enableLoggingAtLevel:BranchLogLevelVerbose];
  2. Observe the logs to ensure that messages are correctly formatted, include the calling class and method where applicable, and that only logs at or above the set threshold are displayed.
  3. Also try the logCallback like this:
    [BranchLogger shared].logCallback = ^(NSString *message, BranchLogLevel logLevel, NSError * _Nullable error) {
        // This block will be called for every log message emitted by the Branch SDK.
         if (error) {
             NSLog(@"[BranchLog] Level: %lu, Message: %@, Error: %@", (unsigned long)logLevel, message, error.localizedDescription);
         } else {
             NSLog(@"[BranchLog] Level: %lu, Message: %@", (unsigned long)logLevel, message);
         }     
    };

cc @BranchMetrics/saas-sdk-devs for visibility.

codecov[bot] commented 7 months ago

Codecov Report

Attention: 153 lines in your changes are missing coverage. Please review.

Comparison is base (9a0722e) 50.60% compared to head (1c4df07) 50.94%. Report is 3 commits behind head on master.

Files Patch % Lines
BranchSDK/BranchLogger.m 69.66% 20 Missing and 7 partials :warning:
BranchSDK/Branch.m 41.02% 23 Missing :warning:
BranchSDK/BranchOpenRequest.m 18.75% 13 Missing :warning:
BranchSDK/BranchQRCode.m 33.33% 12 Missing :warning:
BranchSDK/BNCPreferenceHelper.m 81.48% 4 Missing and 6 partials :warning:
BranchSDK/BNCServerRequestQueue.m 20.00% 8 Missing :warning:
BranchSDK/BNCURLFilter.m 0.00% 7 Missing :warning:
BranchSDK/BNCApplication.m 0.00% 5 Missing and 1 partial :warning:
BranchSDK/BNCKeyChain.m 14.28% 5 Missing and 1 partial :warning:
BranchSDK/BranchEvent.m 33.33% 6 Missing :warning:
... and 15 more
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1346 +/- ## ========================================== + Coverage 50.60% 50.94% +0.34% ========================================== Files 68 67 -1 Lines 10070 10130 +60 Branches 3862 3798 -64 ========================================== + Hits 5096 5161 +65 + Misses 4714 4704 -10 - Partials 260 265 +5 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.