lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /**
|
| 2 | *
|
| 3 | * @file ap_log.c
|
| 4 | * @brief
|
| 5 | * This file is part of ZCAT.
|
| 6 | * zcatÓ¦Óòãlog_agent´¦Àílogcat_printf/logcat_printkÉ豸
|
| 7 | *
|
| 8 | * @details
|
| 9 | * @author Tools Team.
|
| 10 | * @email
|
| 11 | * @copyright Copyright (C) 2013 Sanechips Technology Co., Ltd.
|
| 12 | * @warning
|
| 13 | * @date 2019/02/02
|
| 14 | * @version 1.2
|
| 15 | * @pre
|
| 16 | * @post
|
| 17 | *
|
| 18 | * @par
|
| 19 | * Change History :
|
| 20 | * ---------------------------------------------------------------------------
|
| 21 | * date version author description
|
| 22 | * ---------------------------------------------------------------------------
|
| 23 | * 2017/07/17 1.0 hou.bing Create file
|
| 24 | * 2019/01/24 1.1 jiang.fenglin 1.Ìí¼Óusblog¶ÁÐ´Ëø
|
| 25 | * 2.Ìí¼ÓÏß³ÌÃû³Æ
|
| 26 | * 2019/02/02 1.2 jiang.fenglin ÐÞ¸Ä×¢ÊÍ·½Ê½Îªdoxygen
|
| 27 | * ---------------------------------------------------------------------------
|
| 28 | *
|
| 29 | *
|
| 30 | */
|
| 31 |
|
| 32 | #include <string.h>
|
| 33 | #include <pthread.h>
|
| 34 | #include <sys/prctl.h>
|
| 35 | #include "log_agent.h"
|
| 36 |
|
| 37 | /*É豸·¾¶*/
|
| 38 | const char* kernellog_dev = "/dev/logcat_printk";
|
| 39 | const char* applog_dev = "/dev/logcat_printf";
|
| 40 |
|
| 41 | static BOOL g_KernelNewLine = TRUE;
|
| 42 | static BOOL g_AppNewLine = TRUE;
|
| 43 | extern int hb_flag;
|
| 44 | pthread_t read_kernellog_thread = 0;;
|
| 45 | pthread_t read_applog_thread = 0;;
|
| 46 | int kernellog_fd = -1;
|
| 47 | int applog_fd = -1;
|
| 48 |
|
| 49 | extern void zCatAgt_Ap_GetModAndPri(unsigned char **buf, unsigned short *bufLen, unsigned char *pPriority, unsigned char *pMod);
|
| 50 | extern BOOL zCatAgt_Ap_ReadBuffer(T_AP_SRC_BUFFER_TYPE *src, T_AP_DEST_BUFFER_TYPE *dest);
|
| 51 | extern unsigned int zCatAgt_Ap_SendMsg(unsigned char cmd_code, unsigned char priority, unsigned char mod, unsigned char *buf, unsigned int len);
|
| 52 |
|
| 53 | /**
|
| 54 | * @brief ¶ÁÈ¡applogµÄÏ̺߳¯Êý£¬\n
|
| 55 | * ´¦Àí´Óapplog_devÉ豸ÖеÄlogÊý¾Ý£¬²¢×ª·¢³öÈ¥.
|
| 56 | * @param[in] args Ï̺߳¯Êý²ÎÊý
|
| 57 | * @return void
|
| 58 | * @note
|
| 59 | * @see
|
| 60 | */
|
| 61 | void *read_applog(void* args)
|
| 62 | {
|
| 63 | int read_len = -1;
|
| 64 | static unsigned char readApplogBuffer[4096] = {0};
|
| 65 |
|
| 66 | prctl(PR_SET_NAME, "read_applog");
|
| 67 | //printf("zcat: read_applog \n");
|
| 68 | while(1)
|
| 69 | {
|
| 70 | if(hb_flag)
|
| 71 | read_len = read(applog_fd, readApplogBuffer, sizeof(readApplogBuffer));
|
| 72 | if(read_len>0)
|
| 73 | {
|
| 74 | T_AP_DEST_BUFFER_TYPE dest = {0};
|
| 75 | T_AP_SRC_BUFFER_TYPE src = {0};
|
| 76 | src.buf = readApplogBuffer;
|
| 77 | src.beginIndex=0;
|
| 78 | src.bufSize = read_len;
|
| 79 | //printf("zcat: read_applog read_len %d \n", read_len);
|
| 80 |
|
| 81 | while (zCatAgt_Ap_ReadBuffer(&src , &dest))
|
| 82 | {
|
| 83 | unsigned char *p = dest.buf;
|
| 84 | unsigned short len = dest.len;
|
| 85 | unsigned char priority = APP_LOG_DEFAULT_LEVEL;
|
| 86 | unsigned char mod = 1;
|
| 87 | static unsigned char curPriority = APP_LOG_DEFAULT_LEVEL;
|
| 88 |
|
| 89 | if (g_AppNewLine)
|
| 90 | {
|
| 91 | g_AppNewLine = FALSE;
|
| 92 | zCatAgt_Ap_GetModAndPri(&p, &len, &priority, &mod);
|
| 93 | curPriority = priority;
|
| 94 | }
|
| 95 | else
|
| 96 | {
|
| 97 | priority = curPriority;
|
| 98 | }
|
| 99 | zCatAgt_Ap_SendMsg(ZCAT_AP_APP_LOG, priority, mod, p, len);
|
| 100 | if (dest.newLine == 1)
|
| 101 | {
|
| 102 | g_AppNewLine = TRUE;
|
| 103 | }
|
| 104 | memset(&dest, 0, sizeof(T_AP_DEST_BUFFER_TYPE));
|
| 105 | }
|
| 106 | memset(readApplogBuffer, 0, sizeof(readApplogBuffer));
|
| 107 | }
|
| 108 | else
|
| 109 | {
|
| 110 | sleep(1);
|
| 111 | }
|
| 112 |
|
| 113 | }
|
| 114 | return NULL;
|
| 115 | }
|
| 116 |
|
| 117 |
|
| 118 | /**
|
| 119 | * @brief ¶ÁÈ¡kernellogµÄÏ̺߳¯Êý£¬\n
|
| 120 | * ´¦Àí´Ókernellog_devÉ豸ÖеÄlogÊý¾Ý£¬²¢×ª·¢³öÈ¥.
|
| 121 | * @param[in] args Ï̺߳¯Êý²ÎÊý
|
| 122 | * @return void
|
| 123 | * @note
|
| 124 | * @see
|
| 125 | */
|
| 126 | void *read_kernellog(void* args)
|
| 127 | {
|
| 128 | int read_len = -1;
|
| 129 | unsigned char readKernelLogBuffer[1024] = {0};
|
| 130 |
|
| 131 | prctl(PR_SET_NAME, "read_kernellog");
|
| 132 | //printf("read_kernellog kkkkkkkkkkkk fd %d\n", fd);
|
| 133 | while(1)
|
| 134 | {
|
| 135 | if(hb_flag)
|
| 136 | read_len = read(kernellog_fd, readKernelLogBuffer, sizeof(readKernelLogBuffer));
|
| 137 | if(read_len > 0)
|
| 138 | {
|
| 139 | T_AP_DEST_BUFFER_TYPE dest = {0};
|
| 140 | T_AP_SRC_BUFFER_TYPE src = {0};
|
| 141 | src.buf = readKernelLogBuffer;
|
| 142 | src.beginIndex=0;
|
| 143 | src.bufSize = read_len;
|
| 144 | //printf("read_kernellog read_len %d \n", read_len);
|
| 145 | //CHAR atCmd[200] = {0};
|
| 146 | //g_cp_log_count++;
|
| 147 | //sprintf(atCmd, " /sbin/atlog.sh \"%s\" \"%s\" \"%s\",\"%d\",\"%d\"", "send",zte_time(),"wubo deal_with_kernellog_from_devkkkkkkkk", read_len, 0);
|
| 148 | //system(atCmd);
|
| 149 | while (zCatAgt_Ap_ReadBuffer(&src , &dest))
|
| 150 | {
|
| 151 | unsigned char *p = dest.buf;
|
| 152 | unsigned short len = dest.len;
|
| 153 | unsigned char priority = KERNEL_LOG_DEFAULT_LEVEL;
|
| 154 | unsigned char mod = 1;
|
| 155 | static unsigned char curPriority = KERNEL_LOG_DEFAULT_LEVEL;
|
| 156 |
|
| 157 | if (g_KernelNewLine)
|
| 158 | {
|
| 159 | g_KernelNewLine = FALSE;
|
| 160 | zCatAgt_Ap_GetModAndPri(&p, &len, &priority, &mod);
|
| 161 | curPriority = priority;
|
| 162 | }
|
| 163 | else
|
| 164 | {
|
| 165 | priority = curPriority;
|
| 166 | }
|
| 167 | zCatAgt_Ap_SendMsg(ZCAT_AP_KERNEL_LOG, priority, mod, p, len);
|
| 168 |
|
| 169 | if (dest.newLine == 1)
|
| 170 | {
|
| 171 | g_AppNewLine = TRUE;
|
| 172 | }
|
| 173 |
|
| 174 | memset(&dest, 0, sizeof(T_AP_DEST_BUFFER_TYPE));
|
| 175 | }
|
| 176 | memset(readKernelLogBuffer, 0, sizeof(readKernelLogBuffer));
|
| 177 | }
|
| 178 | else
|
| 179 | {
|
| 180 | sleep(1);
|
| 181 | }
|
| 182 | }
|
| 183 | }
|
| 184 |
|