• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..17-Mar-2025-

include/H17-Mar-2025-15899

src/H17-Mar-2025-4223

README.mdH A D17-Mar-20251.4 KiB5445

README.md

1## How To Use Log
2
3# C++
41. Add a statement to your gn file
5
6```
7    deps = [
8        "${common_path}/log:appexecfwk_log_source_set",
9    ]
10
11    defines = [
12        "APP_LOG_TAG = \"Appexecfwk_Core\"",
13        "LOG_DOMAIN = 0xD001110",
14    ]
15```
162. Include header file `#include "app_log_wrapper.h"`
173. Control log print level `AppLogWrapper::SetLogLevel(AppLogLevel::DEBUG);` default is DEBUG
184. Example output format `[fileName(functionName)] string`
19```
20    // dynamic control log level
21    AppLogWrapper::SetLogLevel(AppLogLevel::FATAL);
22
23    // The following log statement will not print
24    APP_LOGD("one %{public}d", 1234);
25    APP_LOGI("two %{public}s", "1234");
26    APP_LOGW("three %{private}s", "1234");
27    APP_LOGE("four %{private}s", "1234");
28
29    // The following log statement will print
30    AppLogWrapper::SetLogLevel(AppLogLevel::DEBUG);
31    APP_LOGD("five %{public}d", 1234);
32    APP_LOGI("six %{public}s", "1234");
33    APP_LOGW("seven %{private}s", "1234");
34    APP_LOGE("eight %{private}s", "1234");
35```
36
37# Java
38
391. import dependent in your class
40```
41import ohosos.appexecfwk.utils.AppLog;
42import ohosos.hiviewdfx.HiLogLabel;
43```
44
452. custom HiLogLabel (if you don't custom label, the default will be used)
46```
47private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_CORE, 0xD001110, "AppKit");
48```
49
503. use AppLog interface
51```
52App_Log.d(LABEL, "log %{public}s", "123");
53App_Log.i("log %{public}d", 123);
54```