Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame^] | 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 | #include <log/logger.h> |
| 25 | |
| 26 | #include "LogFake.h" |
| 27 | |
| 28 | // Forward declarations. |
| 29 | class Backtrace; |
| 30 | struct EventTagMap; |
| 31 | struct AndroidLogEntry; |
| 32 | |
| 33 | std::string g_fake_log_buf; |
| 34 | |
| 35 | std::string g_fake_log_print; |
| 36 | |
| 37 | void ResetLogs() { |
| 38 | g_fake_log_buf = ""; |
| 39 | g_fake_log_print = ""; |
| 40 | } |
| 41 | |
| 42 | std::string GetFakeLogBuf() { |
| 43 | return g_fake_log_buf; |
| 44 | } |
| 45 | |
| 46 | std::string GetFakeLogPrint() { |
| 47 | return g_fake_log_print; |
| 48 | } |
| 49 | |
| 50 | extern "C" int __android_log_buf_write(int bufId, int prio, const char* tag, const char* msg) { |
| 51 | g_fake_log_buf += std::to_string(bufId) + ' ' + std::to_string(prio) + ' '; |
| 52 | g_fake_log_buf += tag; |
| 53 | g_fake_log_buf += ' '; |
| 54 | g_fake_log_buf += msg; |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | extern "C" int __android_log_print(int prio, const char* tag, const char* fmt, ...) { |
| 59 | va_list ap; |
| 60 | va_start(ap, fmt); |
| 61 | int val = __android_log_vprint(prio, tag, fmt, ap); |
| 62 | va_end(ap); |
| 63 | |
| 64 | return val; |
| 65 | } |
| 66 | |
| 67 | extern "C" int __android_log_vprint(int prio, const char* tag, const char* fmt, va_list ap) { |
| 68 | g_fake_log_print += std::to_string(prio) + ' '; |
| 69 | g_fake_log_print += tag; |
| 70 | g_fake_log_print += ' '; |
| 71 | |
| 72 | android::base::StringAppendV(&g_fake_log_print, fmt, ap); |
| 73 | |
| 74 | g_fake_log_print += '\n'; |
| 75 | |
| 76 | return 1; |
| 77 | } |
| 78 | |
| 79 | extern "C" log_id_t android_name_to_log_id(const char*) { |
| 80 | return LOG_ID_SYSTEM; |
| 81 | } |
| 82 | |
| 83 | extern "C" struct logger_list* android_logger_list_open(log_id_t, int, unsigned int, pid_t) { |
| 84 | errno = EACCES; |
| 85 | return nullptr; |
| 86 | } |
| 87 | |
| 88 | extern "C" int android_logger_list_read(struct logger_list*, struct log_msg*) { |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | extern "C" EventTagMap* android_openEventTagMap(const char*) { |
| 93 | return nullptr; |
| 94 | } |
| 95 | |
| 96 | extern "C" int android_log_processBinaryLogBuffer( |
| 97 | struct logger_entry*, |
| 98 | AndroidLogEntry*, const EventTagMap*, char*, int) { |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | extern "C" void android_logger_list_free(struct logger_list*) { |
| 103 | } |