feature: support outputting stderr and file logs at the same time

This commit is contained in:
luwenpeng
2024-08-21 14:55:43 +08:00
parent 415c21440f
commit aed2daa1a4
9 changed files with 47 additions and 60 deletions

View File

@@ -17,7 +17,7 @@
#include "packet_parser.h"
#include "packet_dump.h"
#define PACKET_IO_LOG_STATE(format, ...) LOG_STATE("dumpfile", format, ##__VA_ARGS__)
#define PACKET_IO_LOG_FATAL(format, ...) LOG_FATAL("dumpfile", format, ##__VA_ARGS__)
#define PACKET_IO_LOG_ERROR(format, ...) LOG_ERROR("dumpfile", format, ##__VA_ARGS__)
#define MAX_PACKET_QUEUE_SIZE (4096 * 1000)
@@ -157,7 +157,7 @@ static void pcap_pkt_handler(u_char *user, const struct pcap_pkthdr *h, const u_
if (ATOMIC_READ(&handle->io_thread_need_exit))
{
free(pcap_pkt);
PACKET_IO_LOG_STATE("dumpfile io thread need exit");
PACKET_IO_LOG_FATAL("dumpfile io thread need exit");
pcap_breakloop(handle->pcap);
break;
}
@@ -166,7 +166,7 @@ static void pcap_pkt_handler(u_char *user, const struct pcap_pkthdr *h, const u_
if (ATOMIC_READ(&handle->io_thread_need_exit))
{
PACKET_IO_LOG_STATE("dumpfile io thread need exit");
PACKET_IO_LOG_FATAL("dumpfile io thread need exit");
pcap_breakloop(handle->pcap);
}
}
@@ -177,7 +177,7 @@ static int dumpfile_handler(struct dumpfile_io *handle, const char *pcap_file)
char pcap_errbuf[PCAP_ERRBUF_SIZE];
realpath(pcap_file, resolved_path);
PACKET_IO_LOG_STATE("dumpfile %s in-processing", resolved_path)
PACKET_IO_LOG_FATAL("dumpfile %s in-processing", resolved_path)
handle->pcap = pcap_open_offline(resolved_path, pcap_errbuf);
if (handle->pcap == NULL)
@@ -188,7 +188,7 @@ static int dumpfile_handler(struct dumpfile_io *handle, const char *pcap_file)
pcap_loop(handle->pcap, -1, pcap_pkt_handler, (u_char *)handle);
pcap_close(handle->pcap);
PACKET_IO_LOG_STATE("dumpfile %s processed", resolved_path)
PACKET_IO_LOG_FATAL("dumpfile %s processed", resolved_path)
return 0;
}
@@ -210,7 +210,7 @@ static void *dumpfile_thread(void *arg)
struct dumpfile_io *handle = (struct dumpfile_io *)arg;
ATOMIC_SET(&handle->io_thread_is_runing, 1);
PACKET_IO_LOG_STATE("dumpfile io thread is running");
PACKET_IO_LOG_FATAL("dumpfile io thread is running");
if (handle->mode == PACKET_IO_DUMPFILE)
{
@@ -257,7 +257,7 @@ static void *dumpfile_thread(void *arg)
}
erro_out:
PACKET_IO_LOG_STATE("dumpfile io thread processed all pcap files");
PACKET_IO_LOG_FATAL("dumpfile io thread processed all pcap files");
while (ATOMIC_READ(&handle->io_thread_need_exit) == 0)
{
@@ -269,7 +269,7 @@ erro_out:
usleep(1000); // 1ms
}
PACKET_IO_LOG_STATE("dumpfile io thread exit");
PACKET_IO_LOG_FATAL("dumpfile io thread exit");
ATOMIC_SET(&handle->io_thread_is_runing, 0);
return NULL;
@@ -485,7 +485,7 @@ uint16_t dumpfile_io_inject(struct dumpfile_io *handle, uint16_t thr_idx, struct
}
else
{
PACKET_IO_LOG_STATE("dump inject packet: %s", file);
PACKET_IO_LOG_FATAL("dump inject packet: %s", file);
}
packet_free(pkt);
}