• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 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 HIVIEWDFX_HILOG_CPP_H
17 #define HIVIEWDFX_HILOG_CPP_H
18 
19 #include "hiview_log.h"
20 
21 #ifdef __cplusplus
22 
23 namespace OHOS {
24 namespace HiviewDFX {
25 struct HiLogLabel {
26     LogType type;
27     unsigned int domain;
28     const char *tag;
29 };
30 
31 class HiLog final {
32 public:
33     /**
34     * @brief Outputs debug logs.
35     *
36     * @param label Indicates the log label.
37     * @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the
38     * privacy identifier. Specifically, {public} or {private} is added between the % character and the format specifier
39     * in each parameter. \n
40     * @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
41     * in the format string.
42     * @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than <b>0</b>
43     * otherwise.
44     * @since 1.1
45     * @version 1.0
46     */
47     static int Debug(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(printf, 2, 3)));
48     /**
49     * @brief Outputs informational logs.
50     *
51     * @param label Indicates the log label.
52     * @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the
53     * privacy identifier. Specifically, {public} or {private} is added between the % character and the format specifier
54     * in each parameter. \n
55     * @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
56     * in the format string.
57     * @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than <b>0</b>
58     * otherwise.
59     * @since 1.1
60     * @version 1.0
61     */
62     static int Info(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(printf, 2, 3)));
63     /**
64     * @brief Outputs warning logs.
65     *
66     * @param label Indicates the log label.
67     * @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the
68     * privacy identifier. Specifically, {public} or {private} is added between the % character and the format specifier
69     * in each parameter. \n
70     * @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
71     * in the format string.
72     * @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than <b>0</b>
73     * otherwise.
74     * @since 1.1
75     * @version 1.0
76     */
77     static int Warn(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(printf, 2, 3)));
78     /**
79     * @brief Outputs error logs.
80     *
81     * @param label Indicates the log label.
82     * @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the
83     * privacy identifier. Specifically, {public} or {private} is added between the % character and the format specifier
84     * in each parameter. \n
85     * @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
86     * in the format string.
87     * @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than <b>0</b>
88     * otherwise.
89     * @since 1.1
90     * @version 1.0
91     */
92     static int Error(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(printf, 2, 3)));
93     /**
94     * @brief Outputs fatal logs.
95     *
96     * @param label Indicates the log label.
97     * @param fmt Indicates the format string, which is an enhancement of a printf format string and supports the
98     * privacy identifier. Specifically, {public} or {private} is added between the % character and the format specifier
99     * in each parameter. \n
100     * @param... Indicates a list of parameters. The number and type of parameters must map onto the format specifiers
101     * in the format string.
102     * @return Returns <b>0</b> or a larger value if the operation is successful; returns a value smaller than <b>0</b>
103     * otherwise.
104     * @since 1.1
105     * @version 1.0
106     */
107     static int Fatal(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(printf, 2, 3)));
108 };
109 } // namespace HiviewDFX
110 } // namespace OHOS
111 #endif // __cplusplus
112 
113 #endif // HIVIEWDFX_HILOG_CPP_H
114