init_log.h 4.1 KB
Newer Older
Z
zhong_ning 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef INIT_LOG_H
#define INIT_LOG_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Z
zhong_ning 已提交
21
#include <unistd.h>
Z
zhong_ning 已提交
22

X
xionglei6 已提交
23
#include "beget_ext.h"
S
sun_fan 已提交
24

Z
zhong_ning 已提交
25 26 27 28 29 30
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif

Z
zhong_ning 已提交
31
#ifndef INIT_LOG_TAG
Z
zhong_ning 已提交
32
#define INIT_LOG_TAG "Init"
Z
zhong_ning 已提交
33 34
#endif

X
xionglei6 已提交
35
#ifndef INIT_LOG_DOMAIN
X
xionglei6 已提交
36
#define INIT_LOG_DOMAIN (BASE_DOMAIN + 1)
X
fix log  
xionglei6 已提交
37
#endif
S
sun_fan 已提交
38

M
Mupceet 已提交
39
INIT_LOCAL_API void OpenLogDevice(void);
M
Mupceet 已提交
40
INIT_LOCAL_API void InitLog(int logLevel, unsigned int domain, const char *tag, const char *fmt, va_list vargs);
X
add ut  
xionglei6 已提交
41

A
an_xinwei 已提交
42 43 44 45 46 47 48
#ifdef PARAM_BASE
#define INIT_LOGV(fmt, ...)
#define INIT_LOGI(fmt, ...)
#define INIT_LOGW(fmt, ...)
#define INIT_LOGE(fmt, ...)
#define INIT_LOGF(fmt, ...)
#else
X
xionglei6 已提交
49
#define INIT_LOGV(fmt, ...) \
M
Mupceet 已提交
50
    StartupLog(INIT_DEBUG, INIT_LOG_DOMAIN, INIT_LOG_TAG, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
51
#define INIT_LOGI(fmt, ...) \
M
Mupceet 已提交
52
    StartupLog(INIT_INFO, INIT_LOG_DOMAIN, INIT_LOG_TAG, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
53
#define INIT_LOGW(fmt, ...) \
M
Mupceet 已提交
54
    StartupLog(INIT_WARN, INIT_LOG_DOMAIN, INIT_LOG_TAG, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
55
#define INIT_LOGE(fmt, ...) \
M
Mupceet 已提交
56
    StartupLog(INIT_ERROR, INIT_LOG_DOMAIN, INIT_LOG_TAG, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
57
#define INIT_LOGF(fmt, ...) \
M
Mupceet 已提交
58
    StartupLog(INIT_FATAL, INIT_LOG_DOMAIN, INIT_LOG_TAG, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
A
an_xinwei 已提交
59
#endif
X
xionglei6 已提交
60 61 62

#ifndef UNLIKELY
#define UNLIKELY(x)    __builtin_expect(!!(x), 0)
Z
zhong_ning 已提交
63
#endif
Z
zhong_ning 已提交
64

Z
zhong_ning 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78
#define INIT_ERROR_CHECK(ret, statement, format, ...) \
    do {                                                  \
        if (!(ret)) {                                     \
            INIT_LOGE(format, ##__VA_ARGS__);             \
            statement;                                    \
        }                                                 \
    } while (0)

#define INIT_INFO_CHECK(ret, statement, format, ...) \
    do {                                                  \
        if (!(ret)) {                                    \
            INIT_LOGI(format, ##__VA_ARGS__);            \
            statement;                                   \
        }                                          \
X
add ut  
xionglei6 已提交
79 80 81 82 83 84 85 86
    } while (0)

#define INIT_WARNING_CHECK(ret, statement, format, ...) \
    do {                                                  \
        if (!(ret)) {                                     \
            INIT_LOGW(format, ##__VA_ARGS__);             \
            statement;                                    \
        }                                                 \
Z
zhong_ning 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    } while (0)

#define INIT_CHECK(ret, statement) \
    do {                                \
        if (!(ret)) {                  \
            statement;                 \
        }                         \
    } while (0)

#define INIT_CHECK_RETURN_VALUE(ret, result) \
    do {                                \
        if (!(ret)) {                            \
            return result;                       \
        }                                  \
    } while (0)

#define INIT_CHECK_ONLY_RETURN(ret) \
    do {                                \
        if (!(ret)) {                   \
            return;                     \
        } \
    } while (0)
Z
zhong_ning 已提交
109

S
sun_fan 已提交
110 111 112 113 114 115 116
#define INIT_CHECK_ONLY_ELOG(ret, format, ...) \
    do {                                       \
        if (!(ret)) {                          \
            INIT_LOGE(format, ##__VA_ARGS__);  \
        } \
    } while (0)

Z
zhong_ning 已提交
117 118 119 120 121 122 123
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif

#endif // INIT_LOG_H