blob: 436e23c28c97450f601de0a51c3cca8eccb696d9 [file] [log] [blame]
Christopher Ferris723cf9b2017-01-19 20:08:48 -08001/*
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 Ferrisd226a512017-07-14 10:37:19 -070028#include <unwindstack/Log.h>
29
30namespace unwindstack {
Christopher Ferris723cf9b2017-01-19 20:08:48 -080031
32static bool g_print_to_stdout = false;
33
34void log_to_stdout(bool enable) {
35 g_print_to_stdout = enable;
36}
37
38// Send the data to the log.
39void 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 Ferrisd226a512017-07-14 10:37:19 -070056
57} // namespace unwindstack