blob: faeb66c2e6cab69b578e919a9731aab36889adf0 [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
28#include "Log.h"
29
30static bool g_print_to_stdout = false;
31
32void log_to_stdout(bool enable) {
33 g_print_to_stdout = enable;
34}
35
36// Send the data to the log.
37void log(uint8_t indent, const char* format, ...) {
38 std::string real_format;
39 if (indent > 0) {
40 real_format = android::base::StringPrintf("%*s%s", 2 * indent, " ", format);
41 } else {
42 real_format = format;
43 }
44 va_list args;
45 va_start(args, format);
46 if (g_print_to_stdout) {
47 real_format += '\n';
48 vprintf(real_format.c_str(), args);
49 } else {
50 LOG_PRI_VA(ANDROID_LOG_INFO, LOG_TAG, real_format.c_str(), args);
51 }
52 va_end(args);
53}