首页 > 解决方案 > 如何在 react-native 本机模块中使用 Log.d?

问题描述

我想看看某些方法何时在本机模块中被触发。

我已经进口了

import android.util.Log;

在我想将日志写入的 java 文件中。

这是我想记录的方法。

public void play(int frequency, double duration, double amplitude, int mode) {
        BlueManager blueManager = BLueServiceManager.getSharedBlueManager();
        if (blueManager == null || !blueManager.isConnected()) {
            return;
        }

        byte actualFreq = (byte) (frequency / EQ_STEP_SIZE);
        short actualDuration = (short) (duration * 1800);
        blueManager.playTone(actualFreq, actualDuration, amplitude);
    }

我试图添加

Log.d("is this thing working???", "I certainly hope so"); 

方法里面。

我打开了 Android Studio,正在查看 Logcat 窗口。即使我知道我已经访问了该方法,我也没有在任何地方看到我的消息。

在此处输入图像描述

标签: javareact-nativelogginglogcatnative-module

解决方案


在 Logcat 中,我可以看到,您只选择了要显示的“信息”消息。

在此处输入图像描述

Log.d()代表调试消息,因此,不会出现在“info”(Log.i())消息下。

更改它并选择“调试”。你会看到消息。或选择“详细”以查看所有消息,无论哪种类型。


推荐阅读