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

Introduce Debug Logging #568

Merged
merged 14 commits into from
Nov 25, 2024
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Added

- `isDebugLoggingEnabled` and `setDebugLogging(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.
123mpozzi marked this conversation as resolved.
Show resolved Hide resolved

## [0.32.0] - 2024-11-14

### Added
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 setLoggingEnabled(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(setLoggingEnabled:(nonnull BOOL)enabled)

@end
38 changes: 38 additions & 0 deletions ios/DebugModule.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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(setLoggingEnabled:)
func setLoggingEnabled(enabled: Bool) {
rolandkakonyi marked this conversation as resolved.
Show resolved Hide resolved
bridge.uiManager.addUIBlock { [weak self] _, _ in
let defaultMinimumLevel: LogLevel = .warning
if enabled {
DebugConfig.logging.logger?.level = .verbose
} else {
DebugConfig.logging.logger?.level = defaultMinimumLevel
}
123mpozzi marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
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 setDebugLogging(value: boolean): Promise<void> {
rolandkakonyi marked this conversation as resolved.
Show resolved Hide resolved
DebugConfig._isDebugEnabled = value;
await DebugModule.setLoggingEnabled(value);
rolandkakonyi marked this conversation as resolved.
Show resolved Hide resolved
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TypeDoc note: I've discovered we can use @defaultValue 😮

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';
Loading