• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "hilog_adapter.h"
17 #include "ohos_adapter/bridge/ark_web_adapter_webcore_bridge_helper.h"
18 
19 #include "base/include/ark_web_macros.h"
20 
21 namespace OHOS::NWeb {
22 using HiLogAdapterPrintLogFunc = int (*)(uint32_t level, const char* tag, const char* fmt, va_list ap);
23 
PrintLog(LogLevelAdapter level,const char * tag,const char * fmt,...)24 ARK_WEB_NO_SANITIZE int HiLogAdapter::PrintLog(LogLevelAdapter level, const char* tag, const char* fmt, ...)
25 {
26     static HiLogAdapterPrintLogFunc hi_log_adapter_print_log = reinterpret_cast<HiLogAdapterPrintLogFunc>(
27         ArkWeb::ArkWebAdapterWebcoreBridgeHelper::GetInstance().LoadFuncSymbol("HiLogAdapterPrintLog", false));
28     if (!hi_log_adapter_print_log) {
29         return -1;
30     }
31 
32     int ret;
33     va_list ap;
34     va_start(ap, fmt);
35     ret = hi_log_adapter_print_log((uint32_t)level, tag, fmt, ap);
36     va_end(ap);
37     return ret;
38 }
39 
PrintConsoleLog(LogLevelAdapter level,const char * tag,const char * fmt,...)40 ARK_WEB_NO_SANITIZE int HiLogAdapter::PrintConsoleLog(LogLevelAdapter level, const char* tag, const char* fmt, ...)
41 {
42     static HiLogAdapterPrintLogFunc hi_log_adapter_console_log = reinterpret_cast<HiLogAdapterPrintLogFunc>(
43         ArkWeb::ArkWebAdapterWebcoreBridgeHelper::GetInstance().LoadFuncSymbol("HiLogAdapterConsoleLog", false));
44     if (!hi_log_adapter_console_log) {
45         return -1;
46     }
47 
48     int ret;
49     va_list ap;
50     va_start(ap, fmt);
51     ret = hi_log_adapter_console_log((uint32_t)level, tag, fmt, ap);
52     va_end(ap);
53     return ret;
54 }
55 } // namespace OHOS::NWeb
56