feature: packet IO support IP reassembly
This commit is contained in:
45
deps/logger/log.c
vendored
45
deps/logger/log.c
vendored
@@ -28,7 +28,7 @@ struct log_config
|
||||
|
||||
struct logger
|
||||
{
|
||||
char config_file[PATH_MAX];
|
||||
char toml_file[PATH_MAX];
|
||||
struct log_config config;
|
||||
|
||||
int log_fd;
|
||||
@@ -87,15 +87,14 @@ static int str_to_level(const char *level)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int config_parse(struct log_config *config, const char *config_file)
|
||||
{
|
||||
int ret = -1;
|
||||
FILE *fp = NULL;
|
||||
char errbuf[200];
|
||||
char *ptr_output = NULL;
|
||||
char *ptr_file = NULL;
|
||||
char *ptr_level = NULL;
|
||||
char *output = NULL;
|
||||
char *file = NULL;
|
||||
char *level = NULL;
|
||||
const char *ptr;
|
||||
toml_table_t *section = NULL;
|
||||
toml_table_t *table = NULL;
|
||||
@@ -122,20 +121,20 @@ static int config_parse(struct log_config *config, const char *config_file)
|
||||
}
|
||||
|
||||
ptr = toml_raw_in(section, "output");
|
||||
if (ptr == NULL || toml_rtos(ptr, &ptr_output) != 0)
|
||||
if (ptr == NULL || toml_rtos(ptr, &output) != 0)
|
||||
{
|
||||
fprintf(stderr, "(logger) config file %s missing log.output\n", config_file);
|
||||
goto error_out;
|
||||
}
|
||||
if (strcasecmp(ptr_output, "stderr") == 0)
|
||||
if (strcasecmp(output, "stderr") == 0)
|
||||
{
|
||||
config->output = LOG_OUTPUT_STDERR;
|
||||
}
|
||||
else if (strcasecmp(ptr_output, "file") == 0)
|
||||
else if (strcasecmp(output, "file") == 0)
|
||||
{
|
||||
config->output = LOG_OUTPUT_FILE;
|
||||
}
|
||||
else if (strcasecmp(ptr_output, "both") == 0)
|
||||
else if (strcasecmp(output, "both") == 0)
|
||||
{
|
||||
config->output = LOG_OUTPUT_BOTH;
|
||||
}
|
||||
@@ -148,21 +147,21 @@ static int config_parse(struct log_config *config, const char *config_file)
|
||||
if (config->output == LOG_OUTPUT_FILE || config->output == LOG_OUTPUT_BOTH)
|
||||
{
|
||||
ptr = toml_raw_in(section, "file");
|
||||
if (ptr == NULL || toml_rtos(ptr, &ptr_file) != 0)
|
||||
if (ptr == NULL || toml_rtos(ptr, &file) != 0)
|
||||
{
|
||||
fprintf(stderr, "(logger) config file %s missing log.file\n", config_file);
|
||||
goto error_out;
|
||||
}
|
||||
strcpy(config->log_file, ptr_file);
|
||||
strcpy(config->log_file, file);
|
||||
}
|
||||
|
||||
ptr = toml_raw_in(section, "level");
|
||||
if (ptr == NULL || toml_rtos(ptr, &ptr_level) != 0)
|
||||
if (ptr == NULL || toml_rtos(ptr, &level) != 0)
|
||||
{
|
||||
fprintf(stderr, "(logger) config file %s missing log.level\n", config_file);
|
||||
goto error_out;
|
||||
}
|
||||
config->level = (enum log_level)str_to_level(ptr_level);
|
||||
config->level = (enum log_level)str_to_level(level);
|
||||
if ((int)config->level == -1)
|
||||
{
|
||||
fprintf(stderr, "config file %s invalid log.level\n", config_file);
|
||||
@@ -172,17 +171,17 @@ static int config_parse(struct log_config *config, const char *config_file)
|
||||
ret = 0;
|
||||
|
||||
error_out:
|
||||
if (ptr_output)
|
||||
if (output)
|
||||
{
|
||||
free(ptr_output);
|
||||
free(output);
|
||||
}
|
||||
if (ptr_file)
|
||||
if (file)
|
||||
{
|
||||
free(ptr_file);
|
||||
free(file);
|
||||
}
|
||||
if (ptr_level)
|
||||
if (level)
|
||||
{
|
||||
free(ptr_level);
|
||||
free(level);
|
||||
}
|
||||
if (table)
|
||||
{
|
||||
@@ -228,7 +227,7 @@ static int log_file_reopen(struct logger *logger)
|
||||
* Public API
|
||||
******************************************************************************/
|
||||
|
||||
struct logger *log_new(const char *config_file)
|
||||
struct logger *log_new(const char *toml_file)
|
||||
{
|
||||
struct logger *logger = (struct logger *)calloc(1, sizeof(struct logger));
|
||||
if (logger == NULL)
|
||||
@@ -237,8 +236,8 @@ struct logger *log_new(const char *config_file)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(&logger->config_file, config_file, strlen(config_file));
|
||||
if (config_parse(&logger->config, config_file) != 0)
|
||||
memcpy(&logger->toml_file, toml_file, strlen(toml_file));
|
||||
if (config_parse(&logger->config, toml_file) != 0)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
@@ -292,7 +291,7 @@ int log_check_level(struct logger *logger, enum log_level level)
|
||||
void log_reload_level(struct logger *logger)
|
||||
{
|
||||
struct log_config config = {};
|
||||
if (config_parse(&config, logger->config_file) == 0)
|
||||
if (config_parse(&config, logger->toml_file) == 0)
|
||||
{
|
||||
logger->config.level = config.level;
|
||||
fprintf(stderr, "(logger) logger level reload to %s\n", level_str[config.level]);
|
||||
|
||||
2
deps/logger/log_internal.h
vendored
2
deps/logger/log_internal.h
vendored
@@ -9,7 +9,7 @@ extern "C"
|
||||
|
||||
extern __thread struct logger *__thread_local_logger;
|
||||
|
||||
struct logger *log_new(const char *config_file);
|
||||
struct logger *log_new(const char *toml_file);
|
||||
void log_free(struct logger *logger);
|
||||
void log_reload_level(struct logger *logger);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user