logger changes from global static variables to one instance per stellar

This commit is contained in:
luwenpeng
2024-08-23 18:44:17 +08:00
parent 8db2e70c38
commit 4e524a8781
23 changed files with 306 additions and 252 deletions

View File

@@ -7,6 +7,7 @@
#include "utils.h"
#include "packet_dump.h"
#include "session_private.h"
#include "stellar/log.h"
#include "stellar/stellar_mq.h"
#include "stellar/stellar_exdata.h"
@@ -51,6 +52,7 @@ static void log_print(int fd, const char *module, const char *fmt, ...)
struct plugin_ctx
{
struct stellar *st;
struct logger *logger;
int sess_exdata_idx;
int sess_plug_id;
int tcp_topic_id;
@@ -271,6 +273,7 @@ extern "C"
pthread_spin_init(&ctx->lock, PTHREAD_PROCESS_PRIVATE);
ctx->st = st;
ctx->logger = stellar_get_logger(st);
ctx->sess_exdata_idx = stellar_exdata_new_index(st, "DEBUG_PLUGIN_SESS_EXDATA", stellar_exdata_free_default, NULL);
ctx->sess_plug_id = stellar_session_plugin_register(st, on_sess_new, on_sess_free, ctx);
ctx->udp_topic_id = stellar_mq_get_topic_id(st, TOPIC_UDP);
@@ -281,6 +284,7 @@ extern "C"
stellar_session_mq_subscribe(st, ctx->tcp_topic_id, on_sess_tcp_msg, ctx->sess_plug_id);
stellar_session_mq_subscribe(st, ctx->tcp_stream_topic_id, on_sess_tcp_stream_msg, ctx->sess_plug_id);
STELLAR_LOG_FATAL(ctx->logger, "debug plugin", "init");
log_print(ctx->fd, "debug plugin", "init");
return ctx;
@@ -291,6 +295,7 @@ extern "C"
struct plugin_ctx *ctx = (struct plugin_ctx *)plugin_ctx;
if (ctx)
{
STELLAR_LOG_FATAL(ctx->logger, "debug plugin", "exit");
log_print(ctx->fd, "debug plugin", "exit");
if (ctx->fd > 0)
{