Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #include <stdarg.h> |
| 18 | #include <stdint.h> |
| 19 | #include <stdio.h> |
| 20 | |
| 21 | #include <string> |
| 22 | |
| 23 | #define LOG_TAG "unwind" |
| 24 | #include <log/log.h> |
| 25 | |
| 26 | #include <android-base/stringprintf.h> |
| 27 | |
Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 28 | #include <unwindstack/Log.h> |
| 29 | |
| 30 | namespace unwindstack { |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 31 | |
| 32 | static bool g_print_to_stdout = false; |
| 33 | |
| 34 | void log_to_stdout(bool enable) { |
| 35 | g_print_to_stdout = enable; |
| 36 | } |
| 37 | |
| 38 | // Send the data to the log. |
| 39 | void log(uint8_t indent, const char* format, ...) { |
| 40 | std::string real_format; |
| 41 | if (indent > 0) { |
| 42 | real_format = android::base::StringPrintf("%*s%s", 2 * indent, " ", format); |
| 43 | } else { |
| 44 | real_format = format; |
| 45 | } |
| 46 | va_list args; |
| 47 | va_start(args, format); |
| 48 | if (g_print_to_stdout) { |
| 49 | real_format += '\n'; |
| 50 | vprintf(real_format.c_str(), args); |
| 51 | } else { |
| 52 | LOG_PRI_VA(ANDROID_LOG_INFO, LOG_TAG, real_format.c_str(), args); |
| 53 | } |
| 54 | va_end(args); |
| 55 | } |
Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 56 | |
| 57 | } // namespace unwindstack |