• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * Copyright (c) 2022 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 ARKCOMPILER_TOOLCHAIN_COMMON_LOG_WRAPPER_H
17  #define ARKCOMPILER_TOOLCHAIN_COMMON_LOG_WRAPPER_H
18  
19  #include "common/macros.h"
20  
21  #if defined(ENABLE_HILOG)
22  #include "hilog/log.h"
23  #endif
24  
25  namespace OHOS::ArkCompiler::Toolchain {
26  #ifdef LOGF
27  #undef LOGF
28  #endif
29  #ifdef LOGE
30  #undef LOGE
31  #endif
32  #ifdef LOGW
33  #undef LOGW
34  #endif
35  #ifdef LOGI
36  #undef LOGI
37  #endif
38  #ifdef LOGD
39  #undef LOGD
40  #endif
41  
42  #if !defined(ENABLE_HILOG)
43  enum class LogLevel {
44      UNKNOWN,
45      DEFAULT,
46      VERBOSE,
47      DEBUG,
48      INFO,
49      WARN,
50      ERROR,
51      FATAL
52  };
53  class TOOLCHAIN_EXPORT StdLog {
54  public:
55      StdLog() = default;
56      ~StdLog() = default;
57  
58      static void PrintLog(LogLevel level, const char* fmt, ...);
59  };
60  #else
61  static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
62      LOG_CORE,
63      0xD003F00,
64      "ArkCompiler"
65  };
66  #endif
67  
68  #pragma clang diagnostic push
69  #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
70  #if !defined(ENABLE_HILOG)
71  #define LOGF(fmt, ...) StdLog::PrintLog(LogLevel::FATAL, fmt, ##__VA_ARGS__)
72  #define LOGE(fmt, ...) StdLog::PrintLog(LogLevel::ERROR, fmt, ##__VA_ARGS__)
73  #define LOGW(fmt, ...) StdLog::PrintLog(LogLevel::WARN, fmt, ##__VA_ARGS__)
74  #define LOGI(fmt, ...) StdLog::PrintLog(LogLevel::INFO, fmt, ##__VA_ARGS__)
75  #define LOGD(fmt, ...) StdLog::PrintLog(LogLevel::DEBUG, fmt, ##__VA_ARGS__)
76  #else
77  #define LOGF(fmt, ...) OHOS::HiviewDFX::HiLog::Fatal(LABEL, fmt, ##__VA_ARGS__)
78  #define LOGE(fmt, ...) OHOS::HiviewDFX::HiLog::Error(LABEL, fmt, ##__VA_ARGS__)
79  #define LOGW(fmt, ...) OHOS::HiviewDFX::HiLog::Warn(LABEL, fmt, ##__VA_ARGS__)
80  #define LOGI(fmt, ...) OHOS::HiviewDFX::HiLog::Info(LABEL, fmt, ##__VA_ARGS__)
81  #define LOGD(fmt, ...) OHOS::HiviewDFX::HiLog::Debug(LABEL, fmt, ##__VA_ARGS__)
82  #endif
83  #pragma clang diagnostic pop
84  } // namespace OHOS::ArkCompiler::Toolchain
85  #endif // ARKCOMPILER_TOOLCHAIN_COMMON_LOG_WRAPPER_H
86