1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef EVENT_LOGGER_EVENT_LOG_CATCHER_H 16 #define EVENT_LOGGER_EVENT_LOG_CATCHER_H 17 #include <ctime> 18 #include <string> 19 namespace OHOS { 20 namespace HiviewDFX { 21 // do not dynamic alloc any memory in sub class, may cause leakage 22 class EventLogCatcher { 23 public: 24 struct TerminalBinder { 25 int pid; 26 int tid; 27 std::string threadStack; 28 }; 29 std::string name_ = ""; 30 TerminalBinder terminalBinder_ = {0, 0, ""}; 31 EventLogCatcher()32 EventLogCatcher() {}; 33 int GetLogSize() const; 34 int AppendFile(int fd, const std::string &fileName) const; 35 void SetLogSize(int size); 36 void Stop(); ~EventLogCatcher()37 virtual ~EventLogCatcher() {}; 38 // Initialize a logcater and check whether all parameters are matching the log type 39 virtual bool Initialize(const std::string &strParam1, int intParam1, int intParam2); 40 // start catch the log 41 // return the bytes that caught 42 virtual int Catch(int fd, int jsonFd); 43 // return a string that describe the log catcher 44 // should not be longer than 256 bytes 45 virtual std::string GetDescription() const; 46 int GetFdSize(int32_t fd); 47 std::string GetName() const; 48 protected: 49 int logSize_ = -1; 50 time_t catcherStartTime_ = -1; 51 bool useStreamFilter_ = false; 52 volatile bool needStop_ = false; 53 std::string description_ = ""; 54 }; 55 } // namespace HiviewDFX 56 } // namespace OHOS 57 #endif // EVENT_LOGGER_LOG_CATCHER_H 58