Skip to content

Commit

Permalink
Merge pull request #568 from bitmovin/feature/introduce-debugconfig
Browse files Browse the repository at this point in the history
Introduce Debug Logging
  • Loading branch information
rolandkakonyi authored Nov 25, 2024
2 parents a4deda1 + 0b63086 commit 9c56ce5
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Added

- `DebugConfig.isDebugLoggingEnabled` and `DebugConfig.setDebugLoggingEnabled(value: boolean)` to check and set whether debug logging is enabled. Debug logging helps diagnose problems and trace the flow of execution within the Player and **should not be enabled in production** as it may log sensitive or confidential information to the console.

### Changed

- Update Bitmovin's native iOS SDK version to `3.78.0`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.bitmovin.player.reactnative

import com.bitmovin.player.api.DebugConfig
import com.facebook.react.bridge.*
import com.facebook.react.module.annotations.ReactModule

private const val MODULE_NAME = "DebugModule"

@ReactModule(name = MODULE_NAME)
class DebugModule(context: ReactApplicationContext) : BitmovinBaseModule(context) {
override fun getName() = MODULE_NAME

/**
* Enable/disable verbose logging for the console logger.
* @param enabled Whether to set verbose logging as enabled or disabled.
*/
@ReactMethod
fun setDebugLoggingEnabled(enabled: Boolean, promise: Promise) {
promise.unit.resolveOnUiThread {
DebugConfig.isLoggingEnabled = enabled
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class RNPlayerViewPackage : ReactPackage {
BitmovinCastManagerModule(reactContext),
BufferModule(reactContext),
NetworkModule(reactContext),
DebugModule(reactContext),
)
}

Expand Down
7 changes: 7 additions & 0 deletions ios/DebugModule.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_REMAP_MODULE(DebugModule, DebugModule, NSObject)

RCT_EXTERN_METHOD(setDebugLoggingEnabled:(nonnull BOOL)enabled)

@end
33 changes: 33 additions & 0 deletions ios/DebugModule.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import BitmovinPlayer

@objc(DebugModule)
public class DebugModule: NSObject, RCTBridgeModule {
// swiftlint:disable:next implicitly_unwrapped_optional
@objc public var bridge: RCTBridge!

// swiftlint:disable:next implicitly_unwrapped_optional
public static func moduleName() -> String! {
"DebugModule"
}

/// Module requires main thread initialization.
public static func requiresMainQueueSetup() -> Bool {
true
}

// swiftlint:disable:next implicitly_unwrapped_optional
public var methodQueue: DispatchQueue! {
bridge.uiManager.methodQueue
}
}

extension DebugModule {
/// Enable/disable verbose logging for the console logger.
/// - Parameter enabled: Whether to set verbose logging as enabled or disabled.
@objc(setDebugLoggingEnabled:)
func setDebugLoggingEnabled(enabled: Bool) {
bridge.uiManager.addUIBlock { [weak self] _, _ in
DebugConfig.logging.logger?.level = enabled ? .verbose : .warning
}
}
}
56 changes: 56 additions & 0 deletions src/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { NativeModules } from 'react-native';

const DebugModule = NativeModules.DebugModule;

/**
* Global debug configuration for all Bitmovin components.
*/
export class DebugConfig {
private static _isDebugEnabled = false;

/**
* Retrieves the current debug logging state.
*
* @returns `true` if debug logging is enabled, otherwise `false`.
*/
static get isDebugLoggingEnabled(): boolean {
return DebugConfig._isDebugEnabled;
}

/**
* Enables or disables global debug logging for all Bitmovin components.
*
* Debug logging provides detailed information primarily for debugging purposes,
* helping to diagnose problems and trace the flow of execution within the Player.
*
* ### Warning:
* This option **should not be enabled in production** as it may log sensitive or confidential
* information to the console.
*
* ## Platform-Specific Logging Behavior
* ---
* - **iOS:** logs are printed using `NSLog` at the verbose log level.
* - **Android:** logs are printed using `android.util.Log` with the following tags:
* - `BitmovinPlayer`
* - `BitmovinPlayerView`
* - `BitmovinOffline`
* - `BitmovinSource`
* - `BitmovinExoPlayer`
*
* ## Limitations
* ---
* **Android**
* - This flag **must** be set **before** creating any Bitmovin component to take effect.
*
* ## Usage Notes
* ---
* - We recommend setting this flag during your app's initialization phase, such as in the
* application's entry point (e.g. `App.tsx`).
*
* @defaultValue `false`
*/
static async setDebugLoggingEnabled(value: boolean): Promise<void> {
DebugConfig._isDebugEnabled = value;
await DebugModule.setDebugLoggingEnabled(value);
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export * from './liveConfig';
export * from './bufferApi';
export * from './network';
export * from './mediaControlConfig';
export * from './debug';

0 comments on commit 9c56ce5

Please sign in to comment.