-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #568 from bitmovin/feature/introduce-debugconfig
Introduce Debug Logging
- Loading branch information
Showing
7 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters