• 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/log.h"
17 
18 #include <cstdarg>
19 #include <cstdio>
20 
21 int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int domain, const char *tag,
22     const char *fmt, va_list ap);
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 #define HILOG_VA_ARGS_PROCESS(ret, level) \
27     do { \
28         va_list args; \
29         va_start(args, fmt); \
30         (ret) = ::HiLogPrintArgs(label.type, (level), label.domain, label.tag, fmt, args); \
31         va_end(args); \
32     } while (0)
33 
Debug(const HiLogLabel & label,const char * fmt,...)34 int HiLog::Debug(const HiLogLabel &label, const char *fmt, ...)
35 {
36     int ret;
37     HILOG_VA_ARGS_PROCESS(ret, LOG_DEBUG);
38     return ret;
39 }
40 
Info(const HiLogLabel & label,const char * fmt,...)41 int HiLog::Info(const HiLogLabel &label, const char *fmt, ...)
42 {
43     int ret;
44     HILOG_VA_ARGS_PROCESS(ret, LOG_INFO);
45     return ret;
46 }
47 
Warn(const HiLogLabel & label,const char * fmt,...)48 int HiLog::Warn(const HiLogLabel &label, const char *fmt, ...)
49 {
50     int ret;
51     HILOG_VA_ARGS_PROCESS(ret, LOG_WARN);
52     return ret;
53 }
54 
Error(const HiLogLabel & label,const char * fmt,...)55 int HiLog::Error(const HiLogLabel &label, const char *fmt, ...)
56 {
57     int ret;
58     HILOG_VA_ARGS_PROCESS(ret, LOG_ERROR);
59     return ret;
60 }
61 
Fatal(const HiLogLabel & label,const char * fmt,...)62 int HiLog::Fatal(const HiLogLabel &label, const char *fmt, ...)
63 {
64     int ret;
65     HILOG_VA_ARGS_PROCESS(ret, LOG_FATAL);
66     return ret;
67 }
68 } // namespace HiviewDFX
69 } // namespace OHOS
70