1 /* 2 * Copyright (C) 2019 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 #pragma once 17 18 #include <iostream> 19 #include <sstream> 20 #include <string> 21 #include <vector> 22 23 #ifndef FUZZ_LOG_TAG 24 #error "Must define FUZZ_LOG_TAG" 25 #endif 26 27 #define FUZZ_LOG() FuzzLog(FUZZ_LOG_TAG).log() 28 29 #ifdef ENABLE_LOG_FUZZ 30 class FuzzLog { 31 public: FuzzLog(const char * tag)32 FuzzLog(const char* tag) : mTag(tag) {} ~FuzzLog()33 ~FuzzLog() { std::cout << mTag << ": " << mOs.str() << std::endl; } 34 log()35 std::stringstream& log() { return mOs; } 36 37 private: 38 const char* mTag = nullptr; 39 std::stringstream mOs; 40 }; 41 #else 42 class FuzzLog { 43 public: FuzzLog(const char *)44 FuzzLog(const char* /*tag*/) {} 45 template <typename T> 46 FuzzLog& operator<<(const T& /*t*/) { 47 return *this; 48 } log()49 FuzzLog& log() { return *this; } 50 }; 51 #endif 52 53 std::string hexString(const void* bytes, size_t len); 54 std::string hexString(const std::vector<uint8_t>& bytes); 55