1 // Copyright 2022 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://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, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 #pragma once 15 16 #include <log/log.h> 17 18 // This backend supports PW_LOG_MODULE_NAME as a fallback for Android logging's 19 // LOG_TAG if and only if LOG_TAG is not already set. 20 #if !defined(LOG_TAG) && defined(PW_LOG_MODULE_NAME) 21 #define LOG_TAG PW_LOG_MODULE_NAME 22 #endif 23 24 // #define PW_LOG_LEVEL_DEBUG 1 25 #define _PW_LOG_ANDROID_LEVEL_1(...) ALOGD(__VA_ARGS__) 26 27 // #define PW_LOG_LEVEL_INFO 2 28 #define _PW_LOG_ANDROID_LEVEL_2(...) ALOGI(__VA_ARGS__) 29 30 // #define PW_LOG_LEVEL_WARN 3 31 #define _PW_LOG_ANDROID_LEVEL_3(...) ALOGW(__VA_ARGS__) 32 33 // #define PW_LOG_LEVEL_ERROR 4 34 #define _PW_LOG_ANDROID_LEVEL_4(...) ALOGE(__VA_ARGS__) 35 36 // #define PW_LOG_LEVEL_CRITICAL 5 37 #define _PW_LOG_ANDROID_LEVEL_5(...) ALOGE(__VA_ARGS__) 38 39 // #define PW_LOG_LEVEL_FATAL 7 40 #define _PW_LOG_ANDROID_LEVEL_7(...) LOG_ALWAYS_FATAL(__VA_ARGS__) 41 42 #define _PW_HANDLE_LOG(level, module, flags, ...) \ 43 _PW_LOG_ANDROID_LEVEL_##level(__VA_ARGS__) 44 45 // The indirection through _PW_HANDLE_LOG ensures the `level` argument is 46 // expanded. 47 #define PW_HANDLE_LOG(...) _PW_HANDLE_LOG(__VA_ARGS__) 48