如何在react-native原生模块中使用Log.d?

问题描述 投票:0回答:2

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

我已经导入了

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 窗口。尽管我知道我已经访问了该方法,但我在任何地方都看不到我的消息。

java react-native logging logcat native-module
2个回答
1
投票

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

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

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


0
投票

如果您在真实设备上运行应用程序:

Log.d('Notification', 'Log from the app');

你应该通过以下命令开始监听日志:

adb logcat -s Notification:D

注意 Log.d 中的第一个参数,是 logcat 命令的标签。

完整文档在这里:https://developer.android.com/studio/command-line/logcat?hl=fr

© www.soinside.com 2019 - 2024. All rights reserved.