blob: 591022815ed679d525e485d6e4a86510ad1b7f6c [file] [log] [blame]
Pawin Vongmasa36653902018-11-15 00:10:25 -08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef C2UTILS_ANDROID_DEBUG_LOG_H_
18#define C2UTILS_ANDROID_DEBUG_LOG_H_
19
20/*
21 * Android provides logging and debug macros. Redefine them with C2 prefix and add support for
22 * opting out of verbose logs.
23 */
24
25#ifdef C2_LOG_TAG
26#define LOG_TAG C2_LOG_TAG
27#endif
28
29#include <android-base/logging.h>
30
31#ifdef C2_LOG_VERBOSE
32#define C2_LOG(LEVEL) LOG(::android::base::LEVEL)
33#else
34/**
35 * Use as follows:
36 *
37 * #define C2_LOG_TAG "tag"
38 * //#define C2_LOG_VERBOSE // enable verbose logs in this file
39 * #include <C2Debug.h>
40 *
41 * C2_LOG(DEBUG) << expr ...;
42 *
43 * Log levels are: VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL (aborts).
44 *
45 * No endl is required.
46 */
47#define C2_LOG(LEVEL) \
48 (::android::base::LEVEL != ::android::base::VERBOSE) && LOG(::android::base::LEVEL)
49#endif
50
51#define C2_CHECK CHECK
52#define C2_CHECK_LT CHECK_LT
53#define C2_CHECK_LE CHECK_LE
54#define C2_CHECK_EQ CHECK_EQ
55#define C2_CHECK_GE CHECK_GE
56#define C2_CHECK_GT CHECK_GT
57#define C2_CHECK_NE CHECK_NE
58
59#define C2_DCHECK DCHECK
60#define C2_DCHECK_LT DCHECK_LT
61#define C2_DCHECK_LE DCHECK_LE
62#define C2_DCHECK_EQ DCHECK_EQ
63#define C2_DCHECK_GE DCHECK_GE
64#define C2_DCHECK_GT DCHECK_GT
65#define C2_DCHECK_NE DCHECK_NE
66
67#endif // C2UTILS_ANDROID_DEBUG_LOG_H_