Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-2163] Added new BranchLogger class #1346

Merged
merged 12 commits into from
Feb 15, 2024
Merged

[SDK-2163] Added new BranchLogger class #1346

merged 12 commits into from
Feb 15, 2024

Conversation

nsingh-branch
Copy link
Contributor

@nsingh-branch nsingh-branch commented Feb 6, 2024

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

  • New feature (non-breaking change which adds functionality)

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.

@nsingh-branch nsingh-branch requested review from echo-branch and NidhiDixit09 and removed request for echo-branch February 6, 2024 19:02
Copy link

codecov bot commented Feb 6, 2024

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 ⚠️
BranchSDK/Branch.m 41.02% 23 Missing ⚠️
BranchSDK/BranchOpenRequest.m 18.75% 13 Missing ⚠️
BranchSDK/BranchQRCode.m 33.33% 12 Missing ⚠️
BranchSDK/BNCPreferenceHelper.m 81.48% 4 Missing and 6 partials ⚠️
BranchSDK/BNCServerRequestQueue.m 20.00% 8 Missing ⚠️
BranchSDK/BNCURLFilter.m 0.00% 7 Missing ⚠️
BranchSDK/BNCApplication.m 0.00% 5 Missing and 1 partial ⚠️
BranchSDK/BNCKeyChain.m 14.28% 5 Missing and 1 partial ⚠️
BranchSDK/BranchEvent.m 33.33% 6 Missing ⚠️
... and 15 more
Additional details and impacted files
@@            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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

BranchSDK/BranchLogger.m Show resolved Hide resolved
BranchSDK/BranchLogger.h Show resolved Hide resolved
sharedInstance = [[BranchLogger alloc] init];
sharedInstance.loggingEnabled = NO;
sharedInstance.logLevelThreshold = BranchLogLevelDebug;
sharedInstance.includeCallerDetails = YES;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's performance test this prior to setting it to YES by default.

@echo-branch echo-branch merged commit 577089b into master Feb 15, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants