Home | History | Annotate | Download | only in chre_host
      1 /*
      2  * Copyright (C) 2017 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 CHRE_HOST_LOG_H_
     18 #define CHRE_HOST_LOG_H_
     19 
     20 #define LOG_TAG "CHRE"
     21 #include <utils/Log.h>
     22 
     23 /**
     24  * Logs a message to both logcat and stdout. Don't use this directly; prefer one
     25  * of LOGE, LOGW, etc. to populate the level.
     26  *
     27  * @param level log level to pass to ALOG (LOG_ERROR, LOG_WARN, etc.)
     28  * @param format printf-style format string
     29  */
     30 #define CHRE_LOG(level, format, ...)                 \
     31     do {                                             \
     32         ALOG(level, LOG_TAG, format, ##__VA_ARGS__); \
     33         printf("%s:%d : " format "\n", __func__, __LINE__, ##__VA_ARGS__); \
     34     } while (0)
     35 
     36 #define LOGE(format, ...) CHRE_LOG(LOG_ERROR,   format, ##__VA_ARGS__)
     37 #define LOGW(format, ...) CHRE_LOG(LOG_WARN,    format, ##__VA_ARGS__)
     38 #define LOGI(format, ...) CHRE_LOG(LOG_INFO,    format, ##__VA_ARGS__)
     39 #define LOGD(format, ...) CHRE_LOG(LOG_DEBUG,   format, ##__VA_ARGS__)
     40 #define LOGV(format, ...) CHRE_LOG(LOG_VERBOSE, format, ##__VA_ARGS__)
     41 
     42 /**
     43  * Helper to log a library error with a human-readable version of the provided
     44  * error code.
     45  *
     46  * @param message Error message string to log
     47  * @param error_code Standard error code number (EINVAL, etc)
     48  */
     49 #define LOG_ERROR(message, error_code)                              \
     50     do {                                                            \
     51         char error_string[64];                                      \
     52         strerror_r(error_code, error_string, sizeof(error_string)); \
     53         LOGE("%s: %s (%d)\n", message, error_string, error_code);   \
     54     } while (0)
     55 
     56 #endif  // CHRE_HOST_LOG_H_
     57