1 /* 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> 24 25 // Forward declarations. 26 class Backtrace; 27 struct EventTagMap; 28 struct AndroidLogEntry; 29 30 std::string g_fake_log_buf; 31 32 std::string g_fake_log_print; 33 34 void resetLogs() { 35 g_fake_log_buf = ""; 36 g_fake_log_print = ""; 37 } 38 39 std::string getFakeLogBuf() { 40 return g_fake_log_buf; 41 } 42 43 std::string getFakeLogPrint() { 44 return g_fake_log_print; 45 } 46 47 extern "C" int async_safe_format_log(int priority, const char* tag, const char* format, ...) { 48 g_fake_log_print += std::to_string(priority) + ' '; 49 g_fake_log_print += tag; 50 g_fake_log_print += ' '; 51 52 va_list ap; 53 va_start(ap, format); 54 android::base::StringAppendV(&g_fake_log_print, format, ap); 55 va_end(ap); 56 57 g_fake_log_print += '\n'; 58 59 return 0; 60 } 61 62 extern "C" int __android_log_buf_write(int bufId, int prio, const char* tag, const char* msg) { 63 g_fake_log_buf += std::to_string(bufId) + ' ' + std::to_string(prio) + ' '; 64 g_fake_log_buf += tag; 65 g_fake_log_buf += ' '; 66 g_fake_log_buf += msg; 67 return 1; 68 } 69 70 extern "C" int __android_log_print(int prio, const char* tag, const char* fmt, ...) { 71 g_fake_log_print += std::to_string(prio) + ' '; 72 g_fake_log_print += tag; 73 g_fake_log_print += ' '; 74 75 va_list ap; 76 va_start(ap, fmt); 77 android::base::StringAppendV(&g_fake_log_print, fmt, ap); 78 va_end(ap); 79 80 g_fake_log_print += '\n'; 81 82 return 1; 83 } 84 85 extern "C" log_id_t android_name_to_log_id(const char*) { 86 return LOG_ID_SYSTEM; 87 } 88 89 extern "C" struct logger_list* android_logger_list_open(log_id_t, int, unsigned int, pid_t) { 90 errno = EACCES; 91 return nullptr; 92 } 93 94 extern "C" int android_logger_list_read(struct logger_list*, struct log_msg*) { 95 return 0; 96 } 97 98 extern "C" EventTagMap* android_openEventTagMap(const char*) { 99 return nullptr; 100 } 101 102 extern "C" int android_log_processBinaryLogBuffer( 103 struct logger_entry*, 104 AndroidLogEntry*, const EventTagMap*, char*, int) { 105 return 0; 106 } 107 108 extern "C" void android_logger_list_free(struct logger_list*) { 109 } 110