blob: 1dbb2dcb5c2bca21f2b6ea5532c58dfbd8746eeb [file] [log] [blame]
Igor Murashkin767260b2019-09-19 14:48:09 -07001/*
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
22namespace iorap {
23namespace common {
24
25// Log to both Stderr and Logd for convenience when running this from the command line.
26class StderrAndLogdLogger {
27 public:
28 explicit StderrAndLogdLogger(android::base::LogId default_log_id = android::base::MAIN)
Igor Murashkin2f113402019-09-24 13:14:02 -070029#ifdef __ANDROID__
30 : logd_(default_log_id)
31#endif
32 {
Igor Murashkin767260b2019-09-19 14:48:09 -070033 }
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 Murashkin2f113402019-09-24 13:14:02 -070041#ifdef __ANDROID__
Igor Murashkin767260b2019-09-19 14:48:09 -070042 logd_(id, sev, tag, file, line, message);
Igor Murashkin2f113402019-09-24 13:14:02 -070043#endif
Igor Murashkin767260b2019-09-19 14:48:09 -070044 StderrLogger(id, sev, tag, file, line, message);
45 }
46
47 private:
Igor Murashkin2f113402019-09-24 13:14:02 -070048#ifdef __ANDROID__
Igor Murashkin767260b2019-09-19 14:48:09 -070049 ::android::base::LogdLogger logd_;
Igor Murashkin2f113402019-09-24 13:14:02 -070050#endif
Igor Murashkin767260b2019-09-19 14:48:09 -070051};
52
53} // namespace iorap
54} // namespace common
55
56#endif