修改日志不显示日志等级的问题
This commit is contained in:
@@ -60,7 +60,7 @@ void call_logger(int log_num, int thread_num)
|
||||
//MESA_handle_runtime_log(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num);
|
||||
//sleep(1);
|
||||
//MESA_handle_runtime_log(test_handle, RLOG_LV_INFO, "test", "test_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num);
|
||||
MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_FATAL, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||
MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||
//sleep(1);
|
||||
MESA_HANDLE_RUNTIME_LOG(test_handle, RLOG_LV_FATAL, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||
MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_FATAL, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d,struct a =%A", i, thread_num, &a);
|
||||
|
||||
@@ -11,10 +11,6 @@
|
||||
#define MESA_SHM_KEY_MAX (MESA_SHM_KEY_MIN + MESA_SHM_RING_QUEUE_NUM -1)
|
||||
#define MESA_SHM_LOG_BUF_PREFIX_LEN 1024
|
||||
|
||||
#define MESA_SHM_RING_QUEUE_INITIAL 0
|
||||
#define MESA_SHM_RING_QUEUE_IDLE 1
|
||||
#define MESA_SHM_RING_QUEUE_HALF_IDLE 2
|
||||
#define MESA_SHM_RING_QUEUE_USED 3
|
||||
|
||||
|
||||
#define MESA_CONSUMER_RUNNING 1
|
||||
@@ -36,18 +32,17 @@ struct MESA_shm_queue_head{
|
||||
int ovw_idx;
|
||||
};
|
||||
|
||||
|
||||
int MESA_shm_alloc_overview(struct MESA_shm_overview **ovw, int *ovw_id, int **consumer_status);
|
||||
struct MESA_shm_queue_head *MESA_shm_get_ring_queue();
|
||||
void MESA_shm_init_mutex();
|
||||
void MESA_shm_init();
|
||||
void MESA_shm_recycle_ring_queue(struct MESA_shm_queue_head *ring_queue_head);
|
||||
int MESA_shm_copy_buf_to_ring_queue(char *buf, int buflen, struct MESA_shm_queue_head *head, char *log_file, int log_file_len);
|
||||
int MESA_shm_copy_buf_to_ring_queue(char *buf, int buflen, struct MESA_shm_queue_head *head, char *log_file, int log_file_len, int level);
|
||||
int MESA_shm_ring_queue_is_empty(struct MESA_shm_queue_head *head);
|
||||
int MESA_shm_ring_queue_is_full(struct MESA_shm_queue_head *head);
|
||||
void MESA_shm_ring_queue_set_empty(struct MESA_shm_queue_head *head);
|
||||
int MESA_shm_get_consumer_status();
|
||||
void MESA_shm_unlink(struct MESA_shm_overview *ovw, int ovw_shmid);
|
||||
const char *loglevel_to_name(int level);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
#include "list.h"
|
||||
#include "MESA_handle_logger.h"
|
||||
#include "MESA_shm_ring_queue.h"
|
||||
|
||||
#define DEFAUT_BUF_SIZE 256
|
||||
@@ -245,13 +246,14 @@ int check_reopen_log_file(struct log_file_list *node)
|
||||
}
|
||||
|
||||
/*
|
||||
(int)file_len + (str)file + '\0' + (int)payload_len + (str)payload + '\0'
|
||||
(int)file_len + (str)p_file + '\0' + (int)log_level + (int)payload_len + (str)payload + '\0'
|
||||
*/
|
||||
void consumer_ring_queue_to_file(struct MESA_shm_queue_head *head)
|
||||
{
|
||||
int *p_file_len = NULL;
|
||||
int file_len = 0;
|
||||
char *p_file = NULL;
|
||||
int *p_level = NULL;
|
||||
int *p_payload_len = NULL;
|
||||
int payload_len = 0;
|
||||
char *payload = NULL;
|
||||
@@ -277,10 +279,11 @@ void consumer_ring_queue_to_file(struct MESA_shm_queue_head *head)
|
||||
continue ;
|
||||
}
|
||||
}
|
||||
p_payload_len = (int *)(p_file + file_len + 1);
|
||||
p_level = (int *)(p_file + file_len + 1);
|
||||
p_payload_len = p_level + 1;
|
||||
payload_len = *p_payload_len;
|
||||
payload = (char *)(p_payload_len + 1);
|
||||
n = snprintf(buf, sizeof(buf), "%s, %s\n", strtime, payload);
|
||||
n = snprintf(buf, sizeof(buf), "%s, %s, %s\n", strtime, loglevel_to_name(*p_level), payload);
|
||||
write(node->fd, buf, n);
|
||||
head->rd_idx = (head->rd_idx + 1) % head->blknum;
|
||||
}
|
||||
@@ -291,6 +294,7 @@ void consumer_ring_queue_to_terminal(struct MESA_shm_queue_head *head, int produ
|
||||
int *p_file_len = NULL;
|
||||
int file_len = 0;
|
||||
char *p_file = NULL;
|
||||
int *p_level = NULL;
|
||||
int *p_payload_len = NULL;
|
||||
int payload_len = 0;
|
||||
char *payload = NULL;
|
||||
@@ -300,11 +304,12 @@ void consumer_ring_queue_to_terminal(struct MESA_shm_queue_head *head, int produ
|
||||
p_file_len = (int *)((char *)(head + 1) + (head->blksize * head->rd_idx));
|
||||
file_len = *p_file_len;
|
||||
p_file = (char *)(p_file_len + 1);
|
||||
p_payload_len = (int *)(p_file + file_len + 1);
|
||||
p_level = (int *)(p_file + file_len + 1);
|
||||
p_payload_len = p_level + 1;
|
||||
payload_len = *p_payload_len;
|
||||
payload = (char *)(p_payload_len + 1);
|
||||
n = snprintf(buf, sizeof(buf), "pid:%d, %s\n", producer_pid, payload);
|
||||
if(g_cur_tty_fd > 0){
|
||||
n = snprintf(buf, sizeof(buf), "pid:%d, %s, %s\n", producer_pid, loglevel_to_name(*p_level), payload);
|
||||
if(g_cur_tty_fd >= 0){
|
||||
write(g_cur_tty_fd, buf, n);
|
||||
}
|
||||
head->rd_idx = (head->rd_idx + 1) % head->blknum;
|
||||
|
||||
@@ -147,7 +147,7 @@ static void escape_for_zlog(char *in_buf, int buflen)
|
||||
return;
|
||||
}
|
||||
|
||||
static const char *loglevel_to_name(int level)
|
||||
const char *loglevel_to_name(int level)
|
||||
{
|
||||
if (level <= RLOG_LV_DEBUG)
|
||||
return "DEBUG";
|
||||
@@ -352,7 +352,7 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const
|
||||
return ;
|
||||
}
|
||||
portable_vsnprintf(handle, pri->cache_buf, pri->cache_buf_len, fmt, ap);
|
||||
MESA_shm_copy_buf_to_ring_queue(pri->cache_buf, pri->cache_buf_len, pri->ring_queue_head, p_handle->real_log_file,p_handle->real_log_file_len);
|
||||
MESA_shm_copy_buf_to_ring_queue(pri->cache_buf, pri->cache_buf_len, pri->ring_queue_head, p_handle->real_log_file,p_handle->real_log_file_len, level);
|
||||
zlog(p_handle->zc, p_handle->runtime_log_file, strlen(p_handle->runtime_log_file), module, strlen(module), __LINE__, level, "%s", pri->cache_buf);
|
||||
va_end(ap);
|
||||
return ;
|
||||
|
||||
@@ -264,13 +264,14 @@ void MESA_shm_ring_queue_set_empty(struct MESA_shm_queue_head *head)
|
||||
}
|
||||
|
||||
/*
|
||||
(int)file_len + (str)p_file + '\0' + (int)payload_len + (str)payload + '\0'
|
||||
(int)file_len + (str)p_file + '\0' + (int)log_level + (int)payload_len + (str)payload + '\0'
|
||||
*/
|
||||
int MESA_shm_copy_buf_to_ring_queue(char *buf, int buflen, struct MESA_shm_queue_head *head, char *log_file, int log_file_len)
|
||||
int MESA_shm_copy_buf_to_ring_queue(char *buf, int buflen, struct MESA_shm_queue_head *head, char *log_file, int log_file_len, int level)
|
||||
{
|
||||
int available_len = 0;
|
||||
int *p_file_len = 0;
|
||||
char *p_file = NULL;
|
||||
int *p_level = NULL;
|
||||
int *p_payload_len = 0;
|
||||
int payload_len = 0;
|
||||
char *p_payload = NULL;
|
||||
@@ -293,7 +294,9 @@ int MESA_shm_copy_buf_to_ring_queue(char *buf, int buflen, struct MESA_shm_queue
|
||||
p_file = (char *)(p_file_len + 1);
|
||||
memcpy(p_file, log_file, log_file_len);
|
||||
p_file[log_file_len] = '\0';
|
||||
p_payload_len = (int *)(p_file + log_file_len + 1);
|
||||
p_level = (int *)(p_file + log_file_len + 1);
|
||||
*p_level = level;
|
||||
p_payload_len = p_level + 1;
|
||||
*p_payload_len = payload_len;
|
||||
p_payload = (char *)(p_payload_len + 1);
|
||||
memcpy(p_payload, buf, payload_len);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
global: MESA*runtime_log*;GIT_VERSION_*;MESA_shm_alloc*;MESA_handle_fmt_rule_register;MESA_shm_ring_queue*;MESA_shm_unlink;
|
||||
global: MESA*runtime_log*;GIT_VERSION_*;MESA_shm_alloc*;MESA_handle_fmt_rule_register;MESA_shm_ring_queue*;MESA_shm_unlink;loglevel_to_name;
|
||||
local: *;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user