1 /* 2 * Copyright (C) 2025 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 #pragma once 18 19 #include <fstream> 20 #include <sstream> 21 #include <string> 22 23 class HalEventLogger { 24 public: 25 static HalEventLogger& getInstance(); 26 HalEventLogger& log(); 27 void dump_log(int fd); 28 void initialize(); 29 void store_log(); 30 31 template <typename T> 32 HalEventLogger& operator<<(const T& value) { 33 ss << value; 34 return *this; 35 } 36 HalEventLogger& operator<<(std::ostream& (*manip)(std::ostream&)) { 37 if (manip == static_cast<std::ostream& (*)(std::ostream&)>(std::endl)) { 38 ss << std::endl; 39 } 40 return *this; 41 } 42 43 private: HalEventLogger()44 HalEventLogger() {} 45 HalEventLogger(const HalEventLogger&) = delete; 46 HalEventLogger& operator=(const HalEventLogger&) = delete; 47 std::stringstream ss; 48 bool logging_enabled; 49 std::string EventFilePath; 50 };