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 EventLogCatcher()25 EventLogCatcher() {}; 26 int GetLogSize() const; 27 int AppendFile(int fd, const std::string &fileName) const; 28 void SetLogSize(int size); 29 void Stop(); ~EventLogCatcher()30 virtual ~EventLogCatcher() {}; 31 // Initialize a logcater and check whether all parameters are matching the log type 32 virtual bool Initialize(const std::string &strParam1, int intParam1, int intParam2); 33 // start catch the log 34 // return the bytes that caught 35 virtual int Catch(int fd); 36 // return a string that describe the log catcher 37 // should not be longer than 256 bytes 38 virtual std::string GetDescription() const; 39 int GetFdSize(int32_t fd); 40 GetName()41 std::string GetName() const 42 { 43 return name_; 44 } 45 protected: 46 int logSize_ = -1; 47 time_t catcherStartTime_ = -1; 48 bool useStreamFilter_ = false; 49 volatile bool needStop_ = false; 50 std::string description_ = ""; 51 std::string name_ = ""; 52 }; 53 } // namespace HiviewDFX 54 } // namespace OHOS 55 #endif // EVENT_LOGGER_LOG_CATCHER_H 56