Igor Murashkin | 767260b | 2019-09-19 14:48:09 -0700 | [diff] [blame] | 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) |
Igor Murashkin | 2f11340 | 2019-09-24 13:14:02 -0700 | [diff] [blame] | 29 | #ifdef __ANDROID__ |
| 30 | : logd_(default_log_id) |
| 31 | #endif |
| 32 | { |
Igor Murashkin | 767260b | 2019-09-19 14:48:09 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 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) { |
Igor Murashkin | 2f11340 | 2019-09-24 13:14:02 -0700 | [diff] [blame] | 41 | #ifdef __ANDROID__ |
Igor Murashkin | 767260b | 2019-09-19 14:48:09 -0700 | [diff] [blame] | 42 | logd_(id, sev, tag, file, line, message); |
Igor Murashkin | 2f11340 | 2019-09-24 13:14:02 -0700 | [diff] [blame] | 43 | #endif |
Igor Murashkin | 767260b | 2019-09-19 14:48:09 -0700 | [diff] [blame] | 44 | StderrLogger(id, sev, tag, file, line, message); |
| 45 | } |
| 46 | |
| 47 | private: |
Igor Murashkin | 2f11340 | 2019-09-24 13:14:02 -0700 | [diff] [blame] | 48 | #ifdef __ANDROID__ |
Igor Murashkin | 767260b | 2019-09-19 14:48:09 -0700 | [diff] [blame] | 49 | ::android::base::LogdLogger logd_; |
Igor Murashkin | 2f11340 | 2019-09-24 13:14:02 -0700 | [diff] [blame] | 50 | #endif |
Igor Murashkin | 767260b | 2019-09-19 14:48:09 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | } // namespace iorap |
| 54 | } // namespace common |
| 55 | |
| 56 | #endif |