blob: 9a23ac761cf8a78d1f84044312015351fd8ad238 [file] [log] [blame]
Christopher Ferris63860cb2015-11-16 17:30:32 -08001/*
2 * Copyright (C) 2015 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 <errno.h>
18#include <stdarg.h>
19
20#include <string>
21
22#include <android-base/stringprintf.h>
23#include <log/log.h>
Christopher Ferris63860cb2015-11-16 17:30:32 -080024
25// Forward declarations.
26class Backtrace;
27struct EventTagMap;
28struct AndroidLogEntry;
29
30std::string g_fake_log_buf;
31
32std::string g_fake_log_print;
33
34void resetLogs() {
35 g_fake_log_buf = "";
36 g_fake_log_print = "";
37}
38
39std::string getFakeLogBuf() {
40 return g_fake_log_buf;
41}
42
43std::string getFakeLogPrint() {
44 return g_fake_log_print;
45}
46
Christopher Ferris7a3681e2017-04-24 17:48:32 -070047extern "C" int async_safe_format_log(int priority, const char* tag, const char* format, ...) {
Christopher Ferris93bdd6a2018-04-05 11:12:38 -070048 g_fake_log_print += std::to_string(priority) + ' ' + tag + ' ';
Christopher Ferris63860cb2015-11-16 17:30:32 -080049
50 va_list ap;
51 va_start(ap, format);
52 android::base::StringAppendV(&g_fake_log_print, format, ap);
53 va_end(ap);
54
55 g_fake_log_print += '\n';
56
57 return 0;
58}
59
Christopher Ferris93bdd6a2018-04-05 11:12:38 -070060extern "C" int async_safe_write_log(int priority, const char* tag, const char* msg) {
61 g_fake_log_print += std::to_string(priority) + ' ' + tag + ' ' + msg + '\n';
62
63 return 0;
64}
65
Christopher Ferris63860cb2015-11-16 17:30:32 -080066extern "C" int __android_log_buf_write(int bufId, int prio, const char* tag, const char* msg) {
67 g_fake_log_buf += std::to_string(bufId) + ' ' + std::to_string(prio) + ' ';
68 g_fake_log_buf += tag;
69 g_fake_log_buf += ' ';
70 g_fake_log_buf += msg;
71 return 1;
72}
73
74extern "C" int __android_log_print(int prio, const char* tag, const char* fmt, ...) {
75 g_fake_log_print += std::to_string(prio) + ' ';
76 g_fake_log_print += tag;
77 g_fake_log_print += ' ';
78
79 va_list ap;
80 va_start(ap, fmt);
81 android::base::StringAppendV(&g_fake_log_print, fmt, ap);
82 va_end(ap);
83
84 g_fake_log_print += '\n';
85
86 return 1;
87}
88
89extern "C" log_id_t android_name_to_log_id(const char*) {
90 return LOG_ID_SYSTEM;
91}
92
93extern "C" struct logger_list* android_logger_list_open(log_id_t, int, unsigned int, pid_t) {
94 errno = EACCES;
95 return nullptr;
96}
97
98extern "C" int android_logger_list_read(struct logger_list*, struct log_msg*) {
99 return 0;
100}
101
102extern "C" EventTagMap* android_openEventTagMap(const char*) {
103 return nullptr;
104}
105
106extern "C" int android_log_processBinaryLogBuffer(
107 struct logger_entry*,
108 AndroidLogEntry*, const EventTagMap*, char*, int) {
109 return 0;
110}
111
112extern "C" void android_logger_list_free(struct logger_list*) {
113}