1 /* 2 * Copyright (c) 2025 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 #include "faultlog_event_factory.h" 16 17 #include "constants.h" 18 #include "faultlog_cjerror.h" 19 #include "faultlog_event_base.h" 20 #include "faultlog_jserror.h" 21 #include "faultlog_sanitizer.h" 22 #include "faultlog_rust_panic.h" 23 #include "hiview_logger.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 DEFINE_LOG_LABEL(0xD002D11, "Faultlogger"); 28 FaultLogEventFactory()29FaultLogEventFactory::FaultLogEventFactory() 30 { 31 InitializeFaultLogEvents(); 32 } 33 InitializeFaultLogEvents()34void FaultLogEventFactory::InitializeFaultLogEvents() 35 { 36 faultLogEvents["JS_ERROR"] = []() { 37 return std::make_unique<FaultLogJsError>(); 38 }; 39 faultLogEvents["CJ_ERROR"] = []() { 40 return std::make_unique<FaultLogCjError>(); 41 }; 42 faultLogEvents["RUST_PANIC"] = []() { 43 return std::make_unique<FaultLogRustPanic>(); 44 }; 45 faultLogEvents["ADDR_SANITIZER"] = []() { 46 return std::make_unique<FaultLogSanitizer>(); 47 }; 48 } 49 CreateFaultLogEvent(const std::string & eventName)50std::unique_ptr<FaultLogEventInterface> FaultLogEventFactory::CreateFaultLogEvent(const std::string& eventName) 51 { 52 auto it = faultLogEvents.find(eventName); 53 if (it != faultLogEvents.end()) { 54 return it->second(); 55 } 56 return nullptr; 57 } 58 } // namespace HiviewDFX 59 } // namespace OHOS 60