1 /* 2 * Copyright (c) 2022-2024 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 #ifndef NWEB_HILOG_H 17 #define NWEB_HILOG_H 18 19 #include <cstdio> 20 #include <unistd.h> 21 #include <sys/types.h> 22 #include <hilog/log_c.h> 23 24 #define BROWSER_UID_BASE 20000000 25 #define LOG_APP_DOMAIN 0xD004500 26 #define LOG_RENDER_DOMAIN 0xD004501 27 #ifndef HILOG_TAG 28 #define HILOG_TAG "webview" 29 #endif 30 #define FILE_NAME (__builtin_strrchr("/" __FILE__, '/') + 1) 31 #define FUNC_LINE_FMT "[%{public}s:%{public}d] " 32 33 #define WVLOG_D(fmt, ...) do { \ 34 uint32_t domain = LOG_RENDER_DOMAIN; \ 35 if ((getuid() / BROWSER_UID_BASE) != 0) { \ 36 domain = LOG_APP_DOMAIN; \ 37 } \ 38 HILOG_IMPL(LOG_CORE, LOG_DEBUG, domain, HILOG_TAG, FUNC_LINE_FMT fmt, \ 39 FILE_NAME, __LINE__, ##__VA_ARGS__); \ 40 } while (0) 41 42 #define WVLOG_I(fmt, ...) do { \ 43 uint32_t domain = LOG_RENDER_DOMAIN; \ 44 if ((getuid() / BROWSER_UID_BASE) != 0) { \ 45 domain = LOG_APP_DOMAIN; \ 46 } \ 47 HILOG_IMPL(LOG_CORE, LOG_INFO, domain, HILOG_TAG, FUNC_LINE_FMT fmt, \ 48 FILE_NAME, __LINE__, ##__VA_ARGS__); \ 49 } while (0) 50 51 #define WVLOG_W(fmt, ...) do { \ 52 uint32_t domain = LOG_RENDER_DOMAIN; \ 53 if ((getuid() / BROWSER_UID_BASE) != 0) { \ 54 domain = LOG_APP_DOMAIN; \ 55 } \ 56 HILOG_IMPL(LOG_CORE, LOG_WARN, domain, HILOG_TAG, FUNC_LINE_FMT fmt, \ 57 FILE_NAME, __LINE__, ##__VA_ARGS__); \ 58 } while (0) 59 60 #define WVLOG_E(fmt, ...) do { \ 61 uint32_t domain = LOG_RENDER_DOMAIN; \ 62 if ((getuid() / BROWSER_UID_BASE) != 0) { \ 63 domain = LOG_APP_DOMAIN; \ 64 } \ 65 HILOG_IMPL(LOG_CORE, LOG_ERROR, domain, HILOG_TAG, FUNC_LINE_FMT fmt, \ 66 FILE_NAME, __LINE__, ##__VA_ARGS__); \ 67 } while (0) 68 69 #define WVLOG_F(fmt, ...) do { \ 70 uint32_t domain = LOG_RENDER_DOMAIN; \ 71 if ((getuid() / BROWSER_UID_BASE) != 0) { \ 72 domain = LOG_APP_DOMAIN; \ 73 } \ 74 HILOG_IMPL(LOG_CORE, LOG_FATAL, domain, HILOG_TAG, FUNC_LINE_FMT fmt, \ 75 FILE_NAME, __LINE__, ##__VA_ARGS__); \ 76 } while (0) 77 78 #endif // NWEB_HILOG_H 79