aboutsummaryrefslogtreecommitdiff
path: root/chpp/include/chpp/log.h
blob: 285dfd385d2b99d5d4f52d175ee0b02cdc1432c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * 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 CHPP_LOG_H_
#define CHPP_LOG_H_

// Defines CHRE macros that are necessary to compile CHPP (for compilers other
// than GCC / clang)
#ifndef IS_CHPP_BUILD
#define IS_CHPP_BUILD
#endif

#include "chpp/platform/platform_log.h"
#include "chre/util/log_common.h"

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Log errors if the platform does not supply logging macros.
 */

#ifndef CHPP_LOGE
#error "CHPP_LOGE must be defined"
#endif  // CHPP_LOGE

#ifndef CHPP_LOGW
#error "CHPP_LOGW must be defined"
#endif  // CHPP_LOGW

#ifndef CHPP_LOGI
#error "CHPP_LOGI must be defined"
#endif  // CHPP_LOGI

#ifndef CHPP_LOGD
#error "CHPP_LOGD must be defined"
#endif  // CHPP_LOGD

#ifndef CHPP_MINIMUM_LOG_LEVEL
#define CHPP_MINIMUM_LOG_LEVEL CHRE_LOG_LEVEL_DEBUG
#endif  // CHPP_MINIMUM_LOG_LEVEL

#if CHPP_MINIMUM_LOG_LEVEL < CHRE_LOG_LEVEL_ERROR
#undef CHPP_LOGE
#define CHPP_LOGE(format, ...) CHRE_LOG_NULL(format, ##__VA_ARGS__)
#endif

#if CHPP_MINIMUM_LOG_LEVEL < CHRE_LOG_LEVEL_WARN
#undef CHPP_LOGW
#define CHPP_LOGW(format, ...) CHRE_LOG_NULL(format, ##__VA_ARGS__)
#endif

#if CHPP_MINIMUM_LOG_LEVEL < CHRE_LOG_LEVEL_INFO
#undef CHPP_LOGI
#define CHPP_LOGI(format, ...) CHRE_LOG_NULL(format, ##__VA_ARGS__)
#endif

#if CHPP_MINIMUM_LOG_LEVEL < CHRE_LOG_LEVEL_DEBUG
#undef CHPP_LOGD
#define CHPP_LOGD(format, ...) CHRE_LOG_NULL(format, ##__VA_ARGS__)
#endif

/**
 * Logs an out of memory error with file and line number.
 */
#define CHPP_LOG_OOM() CHPP_LOGE("OOM at %s:%d", __FILE__, __LINE__)

#ifdef __cplusplus
}
#endif

#endif  // CHPP_LOG_H_