1 /**
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "logger.h"
17 #include "libpandabase/macros.h"
18 #include <hilog/log.h>
19 #include "plugins/ets/runtime/ani/ani.h"
20
21 namespace ark::ets::ohos {
22
DefaultLogger(FILE * stream,int level,const char * component,const char * msg)23 void DefaultLogger([[maybe_unused]] FILE *stream, int level, const char *component, const char *msg)
24 {
25 #ifdef PANDA_OHOS_USE_INNER_HILOG
26 constexpr static unsigned int ARK_DOMAIN = 0xD003F00;
27 constexpr static auto TAG = "ArkEtsVm";
28 constexpr static OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, ARK_DOMAIN, TAG};
29 switch (level) {
30 case ANI_LOGLEVEL_DEBUG:
31 OHOS::HiviewDFX::HiLog::Debug(LABEL, "%{public}s: %{public}s", component, msg);
32 break;
33 case ANI_LOGLEVEL_INFO:
34 OHOS::HiviewDFX::HiLog::Info(LABEL, "%{public}s: %{public}s", component, msg);
35 break;
36 case ANI_LOGLEVEL_ERROR:
37 OHOS::HiviewDFX::HiLog::Error(LABEL, "%{public}s: %{public}s", component, msg);
38 break;
39 case ANI_LOGLEVEL_FATAL:
40 OHOS::HiviewDFX::HiLog::Fatal(LABEL, "%{public}s: %{public}s", component, msg);
41 break;
42 case ANI_LOGLEVEL_WARNING:
43 OHOS::HiviewDFX::HiLog::Warn(LABEL, "%{public}s: %{public}s", component, msg);
44 break;
45 default:
46 UNREACHABLE();
47 }
48 #else
49 switch (level) {
50 case ANI_LOGLEVEL_DEBUG:
51 OH_LOG_Print(LOG_APP, LOG_DEBUG, 0xFF00, "ArkEtsVm", "%s: %s", component, msg);
52 break;
53 case ANI_LOGLEVEL_INFO:
54 OH_LOG_Print(LOG_APP, LOG_INFO, 0xFF00, "ArkEtsVm", "%s: %s", component, msg);
55 break;
56 case ANI_LOGLEVEL_ERROR:
57 OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "ArkEtsVm", "%s: %s", component, msg);
58 break;
59 case ANI_LOGLEVEL_FATAL:
60 OH_LOG_Print(LOG_APP, LOG_FATAL, 0xFF00, "ArkEtsVm", "%s: %s", component, msg);
61 break;
62 case ANI_LOGLEVEL_WARNING:
63 OH_LOG_Print(LOG_APP, LOG_WARN, 0xFF00, "ArkEtsVm", "%s: %s", component, msg);
64 break;
65 default:
66 UNREACHABLE();
67 }
68 #endif // PANDA_OHOS_USE_INNER_HILOG
69 }
70
71 } // namespace ark::ets::ohos
72