1 /* 2 * Copyright (C) 2019 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 IORAP_SRC_COMMON_LOGGERS 18 #define IORAP_SRC_COMMON_LOGGERS 19 20 #include <android-base/logging.h> 21 22 namespace iorap { 23 namespace common { 24 25 // Log to both Stderr and Logd for convenience when running this from the command line. 26 class StderrAndLogdLogger { 27 public: 28 explicit StderrAndLogdLogger(android::base::LogId default_log_id = android::base::MAIN) 29 #ifdef __ANDROID__ 30 : logd_(default_log_id) 31 #endif 32 { 33 } 34 operator()35 void operator()(::android::base::LogId id, 36 ::android::base::LogSeverity sev, 37 const char* tag, 38 const char* file, 39 unsigned int line, 40 const char* message) { 41 #ifdef __ANDROID__ 42 logd_(id, sev, tag, file, line, message); 43 #endif 44 StderrLogger(id, sev, tag, file, line, message); 45 } 46 47 private: 48 #ifdef __ANDROID__ 49 ::android::base::LogdLogger logd_; 50 #endif 51 }; 52 53 } // namespace iorap 54 } // namespace common 55 56 #endif 57