64 lines
2.2 KiB
C
Executable File
64 lines
2.2 KiB
C
Executable File
#include "cmd_file.h"
|
|
#include "ulog_api.h"
|
|
#include "log_types.h"
|
|
#include "logging_common.h"
|
|
#include "ulog/ulog_in.h"
|
|
#include "s2j/s2j.h"
|
|
|
|
int conf_file(cJSON *json_obj, int argc, char **argv)
|
|
{
|
|
log_file_t log_file = {0};
|
|
log_file.is_compress = LOG_UNCOMPRESS;
|
|
|
|
int level = LOG_INFO;
|
|
if (argc >= 3) {
|
|
if ((level = log_str_to_level(argv[2])) < 0) {
|
|
ULOG_WARNING(g_log, "Unknown log level:%s", argv[2]);
|
|
return -1;
|
|
}
|
|
}
|
|
log_file.level = level;
|
|
|
|
if (argc >= 4) {
|
|
strncpy(log_file.path, argv[3], sizeof(log_file.path));
|
|
}
|
|
|
|
if (argc >= 5) {
|
|
if (atoi(argv[4]) > 0) {
|
|
log_file.is_compress = LOG_COMPRESS;
|
|
}
|
|
}
|
|
|
|
if (argc >= 6) {
|
|
int day = atoi(argv[5]);
|
|
if (day > 0) {
|
|
log_file.del_over_days = day;
|
|
} else if (day < 0) {
|
|
ULOG_WARNING(g_log, "Deleting day(%d) mustn't be less than 0", day);
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
if (argc >= 7) {
|
|
if (snprintf(log_file.del_over_size, sizeof(log_file.del_over_size), "%s", argv[6]) < 0) {
|
|
ULOG_ERR(g_log, "Building del max size:%s is filure", argv[6]);
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
s2j_json_set_basic_element(json_obj, &log_file, int, level);
|
|
s2j_json_set_basic_element(json_obj, &log_file, string, path);
|
|
s2j_json_set_basic_element(json_obj, &log_file, int, is_compress);
|
|
s2j_json_set_basic_element(json_obj, &log_file, int, del_over_days);
|
|
s2j_json_set_basic_element(json_obj, &log_file, string, del_over_size);
|
|
|
|
int ret = set_log_conf(json_obj, LOG_CONFIG_FILE);
|
|
if (ret != 0) {
|
|
ULOG_ERR(g_log, "File log which is configured is failure");
|
|
} else {
|
|
ULOG_DEBUG(g_log, "File log whice is configured is success");
|
|
}
|
|
return ret;
|
|
}
|
|
|