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 #ifndef SANITIZERD_LOG_H 17 #define SANITIZERD_LOG_H 18 19 #include <cstdio> 20 #include <cstring> 21 22 #include "reporter.h" 23 #include "hilog/log.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 static constexpr char ASAN_LOG_PATH[] = "/dev/asanlog"; 28 29 static constexpr OHOS::HiviewDFX::HiLogLabel SANITIZERD_LABEL = {LOG_CORE, 0xD002D12, "Sanitizer"}; 30 31 #define FILE_NAME(x) (strrchr(x, '/') ? (strrchr(x, '/') + 1) : (x)) 32 33 #define SANITIZERD_DECORATOR_HILOG(op, fmt, args...) \ 34 do { \ 35 op(SANITIZERD_LABEL, "[%{public}s:%{public}d] " fmt, FILE_NAME(__FILE__), __LINE__, ##args); \ 36 } while (0) 37 38 #define SANITIZERD_LOGF(fmt, args...) SANITIZERD_DECORATOR_HILOG(OHOS::HiviewDFX::HiLog::Fatal, fmt, ##args) 39 #define SANITIZERD_LOGE(fmt, args...) SANITIZERD_DECORATOR_HILOG(OHOS::HiviewDFX::HiLog::Error, fmt, ##args) 40 #define SANITIZERD_LOGW(fmt, args...) SANITIZERD_DECORATOR_HILOG(OHOS::HiviewDFX::HiLog::Warn, fmt, ##args) 41 #define SANITIZERD_LOGI(fmt, args...) SANITIZERD_DECORATOR_HILOG(OHOS::HiviewDFX::HiLog::Info, fmt, ##args) 42 43 } // namespace HiviewDFX 44 } // namespace OHOS 45 #endif // SANITIZERD_LOG_H 46