1c29fa5a6Sopenharmony_ci/* 2c29fa5a6Sopenharmony_ci * Copyright (c) 2023-2023 Huawei Device Co., Ltd. 3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License. 5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at 6c29fa5a6Sopenharmony_ci * 7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8c29fa5a6Sopenharmony_ci * 9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and 13c29fa5a6Sopenharmony_ci * limitations under the License. 14c29fa5a6Sopenharmony_ci */ 15c29fa5a6Sopenharmony_ci 16c29fa5a6Sopenharmony_ci#ifndef MMI_LOG_H 17c29fa5a6Sopenharmony_ci#define MMI_LOG_H 18c29fa5a6Sopenharmony_ci 19c29fa5a6Sopenharmony_ci#include <cstdarg> 20c29fa5a6Sopenharmony_ci#include <cstdio> 21c29fa5a6Sopenharmony_ci 22c29fa5a6Sopenharmony_cinamespace OHOS { 23c29fa5a6Sopenharmony_cinamespace HiviewDFX { 24c29fa5a6Sopenharmony_cistruct HiLogLabel { 25c29fa5a6Sopenharmony_ci int32_t log; 26c29fa5a6Sopenharmony_ci int32_t domain; 27c29fa5a6Sopenharmony_ci const char* tag; 28c29fa5a6Sopenharmony_ci}; 29c29fa5a6Sopenharmony_ci} // namespace HiviewDFX 30c29fa5a6Sopenharmony_ci} // namespace OHOS 31c29fa5a6Sopenharmony_ci 32c29fa5a6Sopenharmony_ciinline void ReplaceAll(std::string& str, const std::string& what, const std::string& with) 33c29fa5a6Sopenharmony_ci{ 34c29fa5a6Sopenharmony_ci for (size_t pos = 0; str.npos != (pos = str.find(what, pos)); pos += with.size()) { 35c29fa5a6Sopenharmony_ci str.replace(pos, what.size(), with); 36c29fa5a6Sopenharmony_ci } 37c29fa5a6Sopenharmony_ci} 38c29fa5a6Sopenharmony_ci 39c29fa5a6Sopenharmony_ciinline void PrintLog(const OHOS::HiviewDFX::HiLogLabel& label, const char* type, const char* fmt, ...) 40c29fa5a6Sopenharmony_ci{ 41c29fa5a6Sopenharmony_ci std::string fmts{fmt}; 42c29fa5a6Sopenharmony_ci ReplaceAll(fmts, "{public}", ""); 43c29fa5a6Sopenharmony_ci ReplaceAll(fmts, "{private}", ""); 44c29fa5a6Sopenharmony_ci fmts.append("\n"); 45c29fa5a6Sopenharmony_ci va_list args; 46c29fa5a6Sopenharmony_ci va_start(args, fmt); 47c29fa5a6Sopenharmony_ci std::printf("%s/%s: ", label.tag, type); 48c29fa5a6Sopenharmony_ci std::vprintf(fmts.c_str(), args); 49c29fa5a6Sopenharmony_ci va_end(args); 50c29fa5a6Sopenharmony_ci} 51c29fa5a6Sopenharmony_ci 52c29fa5a6Sopenharmony_ci#define MMI_HILOGD(fmt, ...) PrintLog(LABEL, "D", fmt, ##__VA_ARGS__) 53c29fa5a6Sopenharmony_ci#define MMI_HILOGI(fmt, ...) PrintLog(LABEL, "I", fmt, ##__VA_ARGS__) 54c29fa5a6Sopenharmony_ci#define MMI_HILOGW(fmt, ...) PrintLog(LABEL, "W", fmt, ##__VA_ARGS__) 55c29fa5a6Sopenharmony_ci#define MMI_HILOGE(fmt, ...) PrintLog(LABEL, "E", fmt, ##__VA_ARGS__) 56c29fa5a6Sopenharmony_ci#define MMI_HILOGF(fmt, ...) PrintLog(LABEL, "F", fmt, ##__VA_ARGS__) 57c29fa5a6Sopenharmony_ci#define MMI_HILOGDK(fmt, ...) PrintLog(LABEL, "D", fmt, ##__VA_ARGS__) 58c29fa5a6Sopenharmony_ci#define MMI_HILOGIK(fmt, ...) PrintLog(LABEL, "I", fmt, ##__VA_ARGS__) 59c29fa5a6Sopenharmony_ci#define MMI_HILOGWK(fmt, ...) PrintLog(LABEL, "W", fmt, ##__VA_ARGS__) 60c29fa5a6Sopenharmony_ci#define MMI_HILOGEK(fmt, ...) PrintLog(LABEL, "E", fmt, ##__VA_ARGS__) 61c29fa5a6Sopenharmony_ci#define MMI_HILOGFK(fmt, ...) PrintLog(LABEL, "F", fmt, ##__VA_ARGS__) 62c29fa5a6Sopenharmony_ci#define CALL_DEBUG_ENTER (void)LABEL 63c29fa5a6Sopenharmony_ci#define CALL_INFO_TRACE (void)LABEL 64c29fa5a6Sopenharmony_ci#define CALL_TEST_DEBUG (void)LABEL 65c29fa5a6Sopenharmony_ci 66c29fa5a6Sopenharmony_ciconstexpr int32_t LOG_CORE = 0; 67c29fa5a6Sopenharmony_cinamespace OHOS { 68c29fa5a6Sopenharmony_cinamespace MMI { 69c29fa5a6Sopenharmony_ciconstexpr int32_t MMI_LOG_DOMAIN = 0; 70c29fa5a6Sopenharmony_ci} // namespace MMI 71c29fa5a6Sopenharmony_ci} // namespace OHOS 72c29fa5a6Sopenharmony_ci#endif // MMI_LOG_H 73