1 /* 2 * Copyright (c) 2020 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 16 #ifndef HOS_LITE_HIVIEW_OUTPUT_LOG_H 17 #define HOS_LITE_HIVIEW_OUTPUT_LOG_H 18 19 #include "ohos_types.h" 20 #include "log.h" 21 22 #ifdef __cplusplus 23 #if __cplusplus 24 extern "C" { 25 #endif 26 #endif /* End of #ifdef __cplusplus */ 27 28 void InitCoreLogOutput(void); 29 void InitLogOutput(void); 30 void ClearLogOutput(void); 31 32 /** 33 * Output the log to file. 34 * @param data HiLogContent pointer. 35 * @param len log data length. 36 **/ 37 void OutputLog(const uint8 *data, uint32 len); 38 39 /** 40 * Get the log file size. 41 * @retval File size. 42 **/ 43 uint32 GetLogFileSize(void); 44 45 /** 46 * Read the log data form the log file. 47 * @param buf Read buffer. 48 * @param len Read buffer size. 49 * @retval The length of read data. 50 **/ 51 uint32 ReadLogFile(uint8 *buf, uint32 len); 52 53 /** 54 * Formatting log content. 55 * @param outStr Output string buffer. 56 * @param outStrLen Maximum length of the string buffer. 57 * @param pLogContent Pointer to the HiLogContent object. 58 * @retval The actual length of the formatted string. 59 **/ 60 int32 LogContentFmt(char *outStr, int32 outStrLen, const uint8 *pLogContent); 61 62 /* 63 * Interface for flush logs before the system restarts. 64 * @param syncFlag indicates synchronised flush or asynchronous flush. 65 * @attention Use this interface to flush logs to the UART or the files. 66 */ 67 void FlushLog(boolean syncFlag); 68 69 /** 70 * Interface for register the Hilog handle. 71 * @param func Function Pointer. 72 **/ 73 void HiviewRegisterHilogProc(HilogProc func); 74 75 /** 76 * Interface for deregister the Hilog handle. 77 **/ 78 void HiviewUnRegisterHilogProc(HilogProc func); 79 80 /** 81 * Interface for get the Hilog Output to UART or file. 82 * @retval The the hilog output option. 83 **/ 84 uint32 HiviewGetConfigOption(void); 85 86 /** 87 * Add a monitoring function when hilog file is full . 88 * 89 * @param func callback function. 90 * @param dest hilog output target file path. 91 **/ 92 void HiviewRegisterHiLogFileWatcher(FileProc func, const char *dest); 93 94 /** 95 * Remove monitoring of hilog file. 96 * 97 * @param func callback function. 98 **/ 99 void HiviewUnRegisterHiLogFileWatcher(FileProc func); 100 101 /** 102 * Process files according to mode. 103 * 104 * @param dest hilog output target file path. 105 * @param mode file processing mode. 0 for copy hilog file to dest and keep the 106 * content in the source file, 1 for rename hilog file to dest. 107 * @return 0 if success, otherwise -1. 108 **/ 109 int HiLogFileProcImp(const char *dest, uint8 mode); 110 111 /** 112 * Lock the hilog output target file. 113 * 114 **/ 115 void HiLogOutputFileLockImp(void); 116 117 /** 118 * Unlock the hilog output target file. 119 * 120 **/ 121 void HiLogOutputFileUnLockImp(void); 122 123 #ifdef __cplusplus 124 #if __cplusplus 125 } 126 #endif 127 #endif /* End of #ifdef __cplusplus */ 128 129 #endif /* End of #ifndef HOS_LITE_HIVIEW_OUTPUT_LOG_H */ 130