How To Use Log
C++
- Add a statement to your gn file
deps = [
"${common_path}/log:appexecfwk_log_source_set",
]
defines = [
"APP_LOG_TAG = \"Appexecfwk_Core\"",
"LOG_DOMAIN = 0xD001110",
]
- Include header file
#include "app_log_wrapper.h"
- Control log print level
AppLogWrapper::SetLogLevel(AppLogLevel::DEBUG); default is DEBUG
- Example output format
[fileName(functionName)] string
// dynamic control log level
AppLogWrapper::SetLogLevel(AppLogLevel::FATAL);
// The following log statement will not print
APP_LOGD("one %{public}d", 1234);
APP_LOGI("two %{public}s", "1234");
APP_LOGW("three %{private}s", "1234");
APP_LOGE("four %{private}s", "1234");
// The following log statement will print
AppLogWrapper::SetLogLevel(AppLogLevel::DEBUG);
APP_LOGD("five %{public}d", 1234);
APP_LOGI("six %{public}s", "1234");
APP_LOGW("seven %{private}s", "1234");
APP_LOGE("eight %{private}s", "1234");
Java
- import dependent in your class
import ohosos.appexecfwk.utils.AppLog;
import ohosos.hiviewdfx.HiLogLabel;
- custom HiLogLabel (if you don't custom label, the default will be used)
private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_CORE, 0xD001110, "AppKit");
- use AppLog interface
App_Log.d(LABEL, "log %{public}s", "123");
App_Log.i("log %{public}d", 123);