Skip to content

Commit

Permalink
fix(bridge): fix logger setup and ble init
Browse files Browse the repository at this point in the history
  • Loading branch information
aeddi authored and gfanton committed Apr 17, 2019
1 parent 685d5b7 commit 5c3b866
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
Expand Up @@ -24,18 +24,20 @@ public class CoreModule extends ReactContextBaseJavaModule {
private ReactApplicationContext reactContext;
private MobileNotification notificationDriver = Core.getNotificationDriver();
private ConnectivityUpdateHandler connectivity;
private NativeBridge daemon = Core.newNativeBridge();
private NativeBridge daemon = Core.newNativeBridge(this.logger);

public CoreModule(ReactApplicationContext reactContext) {
super(reactContext);

this.reactContext = reactContext;

String storagePath = reactContext.getFilesDir().getAbsolutePath();
try {
Core.getDeviceInfo().setStoragePath(storagePath);
} catch (Exception error) {
logger.format(Level.ERROR, this.getName(), error.getMessage());
}

this.notificationDriver.setNative(new NotificationNative());

connectivity = new ConnectivityUpdateHandler(reactContext);
Expand Down
8 changes: 7 additions & 1 deletion client/react-native/gomobile/core/bridge.go
Expand Up @@ -51,12 +51,18 @@ type NativeBridge struct {

// @FIXME: NewNativeBridge must not panic, for now Initialize and Dial (should) never
// return an error so it safe, but keep an eye on it.
func NewNativeBridge() *NativeBridge {
func NewNativeBridge(loggerNative NativeLogger) *NativeBridge {
bridge := daemon.New()
if _, err := bridge.Initialize(context.Background(), config); err != nil {
panic(err)
}

if err := setupLogger("debug", loggerNative); err != nil {
panic(err)
}

initBleFunc()

iogrpc := helper.NewIOGrpc()
dialer := iogrpc.NewDialer()
listener := iogrpc.Listener()
Expand Down
2 changes: 1 addition & 1 deletion client/react-native/gomobile/core/core.go
Expand Up @@ -76,7 +76,7 @@ func GetPort() (int, error) {
func Initialize(loggerNative NativeLogger, datastorePath string) error {
defer panicHandler()

if err := setupLogger("debug", datastorePath, loggerNative); err != nil {
if err := setupLogger("debug", loggerNative); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions client/react-native/gomobile/core/logger.go
Expand Up @@ -36,7 +36,7 @@ func (mc *mobileCore) Write(entry zapcore.Entry, fields []zapcore.Field) error {
return mc.l.Log(entry.Level.CapitalString(), entry.LoggerName, buff.String())
}

func setupLogger(logLevel, datastorePath string, mlogger NativeLogger) error {
func setupLogger(logLevel string, mlogger NativeLogger) error {
// native logger
nativeEncoderConfig := zap.NewDevelopmentEncoderConfig()
nativeEncoderConfig.LevelKey = ""
Expand All @@ -63,7 +63,7 @@ func setupLogger(logLevel, datastorePath string, mlogger NativeLogger) error {
RingSize: 10 * 1024 * 1024,
LogLevel: logLevel,
LogNamespaces: "*",
LogDirectory: path.Join(datastorePath, "logs"),
LogDirectory: path.Join(DeviceInfo.GetStoragePath(), "logs"),
AdditionalCores: []zapcore.Core{nativeCore},
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion client/react-native/ios/modules/core/CoreModule.swift
Expand Up @@ -20,7 +20,7 @@ var logger = Logger("chat.berty.io", "CoreModule")
class CoreModule: NSObject {
let connectivity = ConnectivityUpdateHandler()
let serialCoreQueue = DispatchQueue(label: "BertyCore")
let daemon = CoreNewNativeBridge()
let daemon = CoreNewNativeBridge(logger)

@objc func invoke(_ method: NSString, message: NSString, resolve: RCTPromiseResolveBlock!, reject: RCTPromiseRejectBlock!) {
self.serialCoreQueue.sync {
Expand Down

0 comments on commit 5c3b866

Please sign in to comment.