Mod aaa-12 缩进由4个空格代替tab

RCA:
SOL:
修改人:liangxia
检视人:
This commit is contained in:
liangxia 2019-09-09 14:47:51 +08:00
parent dff4a537f2
commit 6e6f8726ed
22 changed files with 1855 additions and 1856 deletions

View File

@ -11,12 +11,12 @@ klog_t *klog_init(const char *module_name)
{
klog_t *log = NULL;
u32 len = 0;
if(NULL == module_name) {
return NULL;
}
len = strlen(module_name);
if(NULL == module_name) {
return NULL;
}
len = strlen(module_name);
if (len > MAX_MODULE_NAME_SZ) {
printk(KERN_ERR"The length:%d of module_name must be not more than %d, but input module_name is %s", len, MAX_MODULE_NAME_SZ, module_name);
@ -28,9 +28,9 @@ klog_t *klog_init(const char *module_name)
printk(KERN_ERR"Allocating log memory is failure");
return NULL;
}
memset(log->module_name, '\0', MAX_MODULE_NAME_SZ+1);
memset(log->module_name, '\0', MAX_MODULE_NAME_SZ+1);
strncpy(log->module_name, module_name, len);
return log;
}
@ -45,17 +45,17 @@ void klog_record(const klog_t *log, const char* level_str, const char *fmt, ...)
{
char log_buf[LOG_MSG_SZ];
va_list args;
va_start(args, fmt);
vsnprintf(log_buf, sizeof(log_buf), fmt, args);
va_end(args);
if (NULL != log) {
printk("%s"MODULE_FMT" %s", level_str, log->module_name, log_buf) ;
}
else {
printk("%s %s", level_str, log_buf) ;
}
if (NULL != log) {
printk("%s"MODULE_FMT" %s", level_str, log->module_name, log_buf) ;
}
else {
printk("%s %s", level_str, log_buf) ;
}
}
EXPORT_SYMBOL_GPL(klog_init);
@ -65,18 +65,18 @@ EXPORT_SYMBOL_GPL(klog_record);
static int __init klog_api_init(void)
{
g_klog = klog_init("klog_api");
g_klog = klog_init("klog_api");
KLOG_INFO(g_klog, "Klog is initiated");
KLOG_INFO(g_klog, "Klog is initiated");
return 0;
}
static void __exit klog_api_exit(void)
{
KLOG_INFO(g_klog, "Klog is exited");
KLOG_INFO(g_klog, "Klog is exited");
klog_close(g_klog);
klog_close(g_klog);
}
module_init(klog_api_init);

View File

@ -5,32 +5,32 @@ klog_t *g_klog = NULL;
static void test_klog_api(const char *module_name)
{
g_klog = klog_init(module_name);
KLOG_DEBUG (g_klog, "test for klog_api %s", "debug");
KLOG_INFO (g_klog, "test for klog_api %s", "info");
KLOG_NOTICE (g_klog, "test for klog_api %s", "notice");
KLOG_WARNING(g_klog, "test for klog_api %s", "warning");
KLOG_ERR (g_klog, "test for klog_api %s", "err");
KLOG_CRIT (g_klog, "test for klog_api %s", "crit");
KLOG_ALERT (g_klog, "test for klog_api %s", "alert");
KLOG_EMERG (g_klog, "test for klog_api %s", "emerg");
g_klog = klog_init(module_name);
klog_close(g_klog);
KLOG_DEBUG (g_klog, "test for klog_api %s", "debug");
KLOG_INFO (g_klog, "test for klog_api %s", "info");
KLOG_NOTICE (g_klog, "test for klog_api %s", "notice");
KLOG_WARNING(g_klog, "test for klog_api %s", "warning");
KLOG_ERR (g_klog, "test for klog_api %s", "err");
KLOG_CRIT (g_klog, "test for klog_api %s", "crit");
KLOG_ALERT (g_klog, "test for klog_api %s", "alert");
KLOG_EMERG (g_klog, "test for klog_api %s", "emerg");
klog_close(g_klog);
}
static int __init test_klog_api_init(void)
{
printk(KERN_INFO"Test-klog_api is initiated");
test_klog_api("test_klog_api");
test_klog_api(NULL);
test_klog_api("");
test_klog_api("a");
test_klog_api("123456789012345");
test_klog_api("1234567890123456");
test_klog_api("12345678901234567");
test_klog_api("test_klog_api");
test_klog_api(NULL);
test_klog_api("");
test_klog_api("a");
test_klog_api("123456789012345");
test_klog_api("1234567890123456");
test_klog_api("12345678901234567");
return 0;
}

View File

@ -16,7 +16,7 @@ ret_code log_rpc_exec(char* service_name, char* method_name, pointer input, int
ret_code ret = rpc_client_recall(&g_log_client, RPC_MODULE_SYSLOG_NAME, service_name,
method_name, input, input_len, NULL, NULL);
if (ret != RET_OK) {
if (ret != RET_OK) {
ULOG_ERR(g_log_h, "rpc call is failure[ret:%u, service:%s, method:%s]", ret, service_name, method_name);
}
@ -28,350 +28,350 @@ ret_code log_rpc_exec(char* service_name, char* method_name, pointer input, int
ret_code cm_log_get_keyvalue_from_file(const char *file_str, const char *key_str, char *value_str, int value_len)
{
ret_code ret = RET_ERR;
FILE *fp = NULL;
char *pos = NULL;
FILE *fp = NULL;
char *pos = NULL;
if (NULL == file_str || '\0' == file_str[0] || NULL == key_str || (NULL == value_str && value_len>0))
{
ULOG_ERR(g_log_h, "get log key-value from file: bad input");
return ret;
}
fp = fopen(file_str, "r");
if (NULL == fp) {
return ret;
}
if (NULL == file_str || '\0' == file_str[0] || NULL == key_str || (NULL == value_str && value_len>0))
{
ULOG_ERR(g_log_h, "get log key-value from file: bad input");
return ret;
}
fp = fopen(file_str, "r");
if (NULL == fp) {
return ret;
}
if (fseek(fp, 0, SEEK_SET) == -1)
{
{
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
fclose(fp);
fclose(fp);
return ret;
}
ssize_t n;
ssize_t n;
char *line = NULL;
while ((getline(&line, &n, fp)) != -1)
{
pos = strstr(line, key_str);
if (pos != NULL)
{
/* 跳过key与value间的"=" */
strcpy(value_str, pos+strlen(key_str)+1);
/* 滤除掉段尾的回车换行 */
if ('\n' == value_str[strlen(value_str)-1])
{
value_str[strlen(value_str)-1] = '\0';
}
{
pos = strstr(line, key_str);
if (pos != NULL)
{
/* 跳过key与value间的"=" */
strcpy(value_str, pos+strlen(key_str)+1);
/* 滤除掉段尾的回车换行 */
if ('\n' == value_str[strlen(value_str)-1])
{
value_str[strlen(value_str)-1] = '\0';
}
ULOG_DEBUG(g_log_h, "get config %s:%s", key_str, value_str);
break;
}
ULOG_DEBUG(g_log_h, "get config %s:%s", key_str, value_str);
break;
}
}
if (NULL!= line)
{
free(line);
}
if (NULL!= line)
{
free(line);
}
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
return ret;
}
/* 检查的文件存在本函数返回1否则本函数返回0 */
int cm_log_check_file_is_exist(const char *file_str)
{
int is_exist = 0;
if (NULL == file_str || '\0' == file_str[0])
{
is_exist = 0;
}
else
{
/* 如果文件存在access返回0不存在access返回-1 */
is_exist = ((access(file_str, 0) == 0) ? 1 : 0);
}
return is_exist;
}
{
int is_exist = 0;
if (NULL == file_str || '\0' == file_str[0])
{
is_exist = 0;
}
else
{
/* 如果文件存在access返回0不存在access返回-1 */
is_exist = ((access(file_str, 0) == 0) ? 1 : 0);
}
return is_exist;
}
/* 适用于log-console.conf、log-pty.conf的解析
* :
* :msg,contains,"[module_test]"
* *.=emerg;*.=alert;*.=crit;*.=err;*.=warn;*.=notice;*.=info;*.=debug /dev/pts/0
* : module_test
* :msg,contains,"[module_test]"
* *.=emerg;*.=alert;*.=crit;*.=err;*.=warn;*.=notice;*.=info;*.=debug /dev/pts/0
* : module_test
*/
ret_code cm_log_get_module_from_file(const char *file_str, char *value_str, uint value_len)
{
ret_code ret = RET_ERR;
FILE *fp = NULL;
char *pos = NULL;
char *pos2 = NULL;
int tmp_len = 0;
FILE *fp = NULL;
char *pos = NULL;
char *pos2 = NULL;
int tmp_len = 0;
if (NULL == file_str || '\0' == file_str[0] || NULL == value_str || 0 == value_len)
{
ULOG_ERR(g_log_h, "get log module from file: bad input");
return ret;
}
fp = fopen(file_str, "r");
if (NULL == fp)
{
return ret;
}
if (NULL == file_str || '\0' == file_str[0] || NULL == value_str || 0 == value_len)
{
ULOG_ERR(g_log_h, "get log module from file: bad input");
return ret;
}
fp = fopen(file_str, "r");
if (NULL == fp)
{
return ret;
}
if (fseek(fp, 0, SEEK_SET) == -1)
{
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
fclose(fp);
return ret;
{
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
fclose(fp);
return ret;
}
ssize_t n;
ssize_t n;
char *line = NULL;
while ((getline(&line, &n, fp)) != -1)
{
pos = strstr(line, "\"[");
if (NULL==pos)
{
continue;
}
pos2 = strstr(line, "]\"");
if (NULL==pos2)
{
continue;
}
{
pos = strstr(line, "\"[");
if (NULL==pos)
{
continue;
}
pos2 = strstr(line, "]\"");
if (NULL==pos2)
{
continue;
}
tmp_len = pos2-pos-strlen("\"[");
if (tmp_len>0 && tmp_len < value_len)
{
strncpy(value_str, pos+strlen("\"["), tmp_len);
value_str[tmp_len] = '\0';
tmp_len = pos2-pos-strlen("\"[");
if (tmp_len>0 && tmp_len < value_len)
{
strncpy(value_str, pos+strlen("\"["), tmp_len);
value_str[tmp_len] = '\0';
ULOG_DEBUG(g_log_h, "get module: %s", value_str);
break;
}
ULOG_DEBUG(g_log_h, "get module: %s", value_str);
break;
}
}
if (NULL!= line)
{
free(line);
if (NULL!= line)
{
free(line);
}
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
return ret;
}
/* 适用于log-console.conf、log-pty.conf、log-file.conf的解析
* :
* *.=emerg;*.=alert;*.=crit;*.=err;*.=warn;*.=notice;*.=info;*.=debug /dev/ttyS0
* : debug
* *.=emerg;*.=alert;*.=crit;*.=err;*.=warn;*.=notice;*.=info;*.=debug /dev/ttyS0
* : debug
*/
ret_code cm_log_get_level_from_file(const char *file_str, u8 *value)
{
ret_code ret = RET_ERR;
FILE *fp = NULL;
ssize_t n;
char *line = NULL;
char *sub_line = NULL;
char *pos = NULL;
char *pos2 = NULL;
size_t tmp_len = 0;
char tmp_str[128] = "";
int tmp_value;
ret_code ret = RET_ERR;
FILE *fp = NULL;
ssize_t n;
char *line = NULL;
char *sub_line = NULL;
char *pos = NULL;
char *pos2 = NULL;
size_t tmp_len = 0;
char tmp_str[128] = "";
int tmp_value;
if (NULL == file_str || '\0' == file_str[0] || NULL == value)
{
ULOG_ERR(g_log_h, "get log level from file: bad input");
}
if (NULL == file_str || '\0' == file_str[0] || NULL == value)
{
ULOG_ERR(g_log_h, "get log level from file: bad input");
}
fp = fopen(file_str, "r");
if (NULL == fp)
{
return ret;
}
fp = fopen(file_str, "r");
if (NULL == fp)
{
return ret;
}
if (fseek(fp, 0, SEEK_SET) == -1)
{
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
fclose(fp);
return ret;
}
if (fseek(fp, 0, SEEK_SET) == -1)
{
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
fclose(fp);
return ret;
}
while ((getline(&line, &n, fp)) != -1)
{
pos = line;
if (NULL == strstr(pos, ".="))
{
continue;
}
while (1)
{
sub_line = strstr(pos, ".=");
if (NULL == sub_line)
{
break;
}
if (strlen(sub_line) <= strlen(".="))
{
break;
}
pos = sub_line+strlen(".=");
}
while ((getline(&line, &n, fp)) != -1)
{
pos = line;
if (NULL == strstr(pos, ".="))
{
continue;
}
while (1)
{
sub_line = strstr(pos, ".=");
if (NULL == sub_line)
{
break;
}
if (strlen(sub_line) <= strlen(".="))
{
break;
}
pos = sub_line+strlen(".=");
}
if (pos != NULL)
{
pos2 = strstr(pos, " ");
if (pos2 != NULL)
{
tmp_len = pos2-pos;
}
else
{
tmp_len = strlen(pos);
}
strncpy(tmp_str, pos, tmp_len);
tmp_str[tmp_len] = '\0';
if (pos != NULL)
{
pos2 = strstr(pos, " ");
if (pos2 != NULL)
{
tmp_len = pos2-pos;
}
else
{
tmp_len = strlen(pos);
}
strncpy(tmp_str, pos, tmp_len);
tmp_str[tmp_len] = '\0';
tmp_value = log_str_to_level(tmp_str);
if( -1 == tmp_value)
{
continue;
}
*value = (u8)tmp_value;
tmp_value = log_str_to_level(tmp_str);
if( -1 == tmp_value)
{
continue;
}
*value = (u8)tmp_value;
ULOG_DEBUG(g_log_h, "get level: %u", *value);
break;
}
}
ULOG_DEBUG(g_log_h, "get level: %u", *value);
break;
}
}
if (NULL != line)
{
free(line);
}
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
return ret;
if (NULL != line)
{
free(line);
}
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
return ret;
}
/* 适用于log-file.conf的解析
* :
* *.=emerg;*.=alert;*.=crit;*.=err;*.=warn;*.=notice;*.=info;*.=debug /etc/rsyslog.d/filetest.conf
* : /etc/rsyslog.d/filetest.conf
* *.=emerg;*.=alert;*.=crit;*.=err;*.=warn;*.=notice;*.=info;*.=debug /etc/rsyslog.d/filetest.conf
* : /etc/rsyslog.d/filetest.conf
*/
ret_code cm_log_get_path_from_file(const char *file_str, char *value_str, uint value_len)
{
ret_code ret = RET_ERR;
FILE *fp = NULL;
ssize_t n;
ret_code ret = RET_ERR;
FILE *fp = NULL;
ssize_t n;
char *line = NULL;
char *sub_line = NULL;
char *pos = NULL;
size_t tmp_len = 0;
char *sub_line = NULL;
char *pos = NULL;
size_t tmp_len = 0;
if (NULL == file_str || '\0' == file_str[0] || NULL == value_str || 0 == value_len)
{
ULOG_ERR(g_log_h, "get log path from file: bad input");
return ret;
}
if (NULL == file_str || '\0' == file_str[0] || NULL == value_str || 0 == value_len)
{
ULOG_ERR(g_log_h, "get log path from file: bad input");
return ret;
}
fp = fopen(file_str, "r");
if (NULL == fp)
{
return ret;
}
fp = fopen(file_str, "r");
if (NULL == fp)
{
return ret;
}
if (fseek(fp, 0, SEEK_SET) == -1)
{
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
fclose(fp);
return ret;
}
if (fseek(fp, 0, SEEK_SET) == -1)
{
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
fclose(fp);
return ret;
}
while ((getline(&line, &n, fp)) != -1)
{
pos = line;
if (NULL == strstr(pos, ".="))
{
continue;
}
while ((getline(&line, &n, fp)) != -1)
{
pos = line;
if (NULL == strstr(pos, ".="))
{
continue;
}
/* 找到最后一个空格 */
while (1)
{
sub_line = strstr(pos, " ");
if (NULL == sub_line)
{
break;
}
if (strlen(sub_line) <= strlen(" "))
{
break;
}
pos = sub_line+strlen(" ");
}
/* 找到最后一个空格 */
while (1)
{
sub_line = strstr(pos, " ");
if (NULL == sub_line)
{
break;
}
if (strlen(sub_line) <= strlen(" "))
{
break;
}
pos = sub_line+strlen(" ");
}
if (pos != NULL)
{
tmp_len = strlen(pos);
if (tmp_len < value_len)
{
strncpy(value_str, pos, tmp_len);
value_str[tmp_len] = '\0';
/* 需要滤除掉行尾的换行符 */
if ('\n' == value_str[tmp_len-1])
{
value_str[tmp_len-1] = '\0';
}
}
break;
}
}
if (pos != NULL)
{
tmp_len = strlen(pos);
if (tmp_len < value_len)
{
strncpy(value_str, pos, tmp_len);
value_str[tmp_len] = '\0';
/* 需要滤除掉行尾的换行符 */
if ('\n' == value_str[tmp_len-1])
{
value_str[tmp_len-1] = '\0';
}
}
break;
}
}
if (NULL != line)
{
free(line);
}
if (NULL != line)
{
free(line);
}
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
return ret;
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
return ret;
}

View File

@ -45,7 +45,7 @@
\
s2j_delete_struct_obj(st); \
cJSON_Delete(json_obj); \
\
\
return RET_OK; \
}

View File

@ -19,102 +19,102 @@ ret_code log_console_config_proc(uint source, uint config_type,
static ret_code cm_get_log_console_elems(log_console_t *log_console_conf, int *err_no)
{
u8 tmp_level = 0;
if (NULL == log_console_conf || NULL == err_no)
{
return RET_ERR;
}
u8 tmp_level = 0;
if (NULL == log_console_conf || NULL == err_no)
{
return RET_ERR;
}
memset(log_console_conf, 0, sizeof(*log_console_conf));
memset(log_console_conf, 0, sizeof(*log_console_conf));
if (cm_log_check_file_is_exist(CM_LOG_CONF_CONSOLE_FILE) != 1)
{
log_console_conf->on = LOG_OFF;
}
else
{
char tmp_module[MAX_MODULE_NAME_SZ] = "";
log_console_conf->on = LOG_ON;
memset(tmp_module, 0, MAX_MODULE_NAME_SZ);
if (cm_log_get_module_from_file(CM_LOG_CONF_CONSOLE_FILE, tmp_module, MAX_MODULE_NAME_SZ) == 0)
{
strncpy(log_console_conf->module, tmp_module, MAX_MODULE_NAME_SZ);
}
if (cm_log_check_file_is_exist(CM_LOG_CONF_CONSOLE_FILE) != 1)
{
log_console_conf->on = LOG_OFF;
}
else
{
char tmp_module[MAX_MODULE_NAME_SZ] = "";
log_console_conf->on = LOG_ON;
memset(tmp_module, 0, MAX_MODULE_NAME_SZ);
if (cm_log_get_module_from_file(CM_LOG_CONF_CONSOLE_FILE, tmp_module, MAX_MODULE_NAME_SZ) == 0)
{
strncpy(log_console_conf->module, tmp_module, MAX_MODULE_NAME_SZ);
}
if (cm_log_get_level_from_file(CM_LOG_CONF_CONSOLE_FILE, &tmp_level) == 0)
{
log_console_conf->level = tmp_level;
}
}
ULOG_DEBUG(g_log_h, "get log console :level=%u, is_on=%s, module=%s",
log_console_conf->level,
log_console_conf->on==LOG_ON?"on":"off",
log_console_conf->module);
return RET_OK;
if (cm_log_get_level_from_file(CM_LOG_CONF_CONSOLE_FILE, &tmp_level) == 0)
{
log_console_conf->level = tmp_level;
}
}
ULOG_DEBUG(g_log_h, "get log console :level=%u, is_on=%s, module=%s",
log_console_conf->level,
log_console_conf->on==LOG_ON?"on":"off",
log_console_conf->module);
return RET_OK;
}
static ret_code cm_log_console_format_json(log_console_t *log_console_conf,
pointer output, int *outlen)
{
char *json_log_file = NULL;
char *json_log_file = NULL;
/* create Student JSON object */
s2j_create_json_obj(json_obj);
if (json_obj == NULL)
{
return RET_NOMEM;
}
/* create Student JSON object */
s2j_create_json_obj(json_obj);
if (json_obj == NULL)
{
return RET_NOMEM;
}
s2j_json_set_basic_element(json_obj, log_console_conf, int, level);
s2j_json_set_basic_element(json_obj, log_console_conf, int, on);
s2j_json_set_basic_element(json_obj, log_console_conf, string, module);
s2j_json_set_basic_element(json_obj, log_console_conf, int, level);
s2j_json_set_basic_element(json_obj, log_console_conf, int, on);
s2j_json_set_basic_element(json_obj, log_console_conf, string, module);
json_log_file = cJSON_PrintUnformatted(json_obj);
*outlen = strlen(json_log_file) + 1;
memcpy(output, json_log_file, *outlen);
json_log_file = cJSON_PrintUnformatted(json_obj);
*outlen = strlen(json_log_file) + 1;
memcpy(output, json_log_file, *outlen);
free(json_log_file);
cJSON_Delete(json_obj);
free(json_log_file);
cJSON_Delete(json_obj);
return RET_OK;
return RET_OK;
}
ret_code log_console_config_get(uint source,
pointer input, int input_len,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
log_console_t *log_console_conf = NULL;
int err_no = 0;
log_console_conf = (log_console_t *)input;
ret_code ret = RET_OK;
log_console_t *log_console_conf = NULL;
int err_no = 0;
log_console_conf = (log_console_t *)input;
ret = cm_get_log_console_elems(log_console_conf, &err_no);
ret = cm_get_log_console_elems(log_console_conf, &err_no);
RET_ERR_FORMART(ret, err_no, output, *output_len);
ASSERT_RET(ret);
RET_ERR_FORMART(ret, err_no, output, *output_len);
ASSERT_RET(ret);
cm_log_console_format_json(log_console_conf, output, output_len);
cm_log_console_format_json(log_console_conf, output, output_len);
return ret;
return ret;
}
ret_code log_console_config_getall(uint source,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
log_console_t *log_console_conf = NULL;
log_console_conf = rpc_new(log_console_t, 1);
ret = log_console_config_get(source, (pointer)log_console_conf, sizeof(log_console_t)*1, output, output_len);
rpc_free(log_console_conf);
return ret;
ret_code ret = RET_OK;
log_console_t *log_console_conf = NULL;
log_console_conf = rpc_new(log_console_t, 1);
ret = log_console_config_get(source, (pointer)log_console_conf, sizeof(log_console_t)*1, output, output_len);
rpc_free(log_console_conf);
return ret;
}

View File

@ -11,7 +11,7 @@
S2J_STRUCT_GET_STRING_ELEMENT_N(s, o, del_over_size, MAX_U64_SZ); \
}
#define LOG_CONF_KEY_FILE_MAX_SIZE_STR "file.max_size"
#define LOG_CONF_KEY_FILE_MAX_SIZE_STR "file.max_size"
ret_code log_file_config_chk(uint source, uint *config_type,
pointer input, int *input_len,
@ -31,205 +31,205 @@ ret_code log_file_config_proc(uint source, uint config_type,
static ret_code cm_log_get_logrotate_conf(const char *file_str, log_file_t *ret_conf)
{
ret_code ret = RET_ERR;
FILE *fp = NULL;
ssize_t n;
char *line = NULL;
char *pos = NULL;
ret_code ret = RET_ERR;
FILE *fp = NULL;
ssize_t n;
char *line = NULL;
char *pos = NULL;
if (NULL == file_str || '\0' == file_str[0]
|| NULL == ret_conf)
{
ULOG_ERR(g_log_h, "get logrotate conf from file: bad input");
}
if (NULL == file_str || '\0' == file_str[0]
|| NULL == ret_conf)
{
ULOG_ERR(g_log_h, "get logrotate conf from file: bad input");
}
memset(ret_conf, 0, sizeof(*ret_conf));
memset(ret_conf, 0, sizeof(*ret_conf));
fp = fopen(file_str, "r");
if (NULL == fp)
{
return ret;
}
fp = fopen(file_str, "r");
if (NULL == fp)
{
return ret;
}
if (fseek(fp, 0, SEEK_SET) == -1)
{
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
goto END;
}
if (fseek(fp, 0, SEEK_SET) == -1)
{
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
goto END;
}
/* 解析日志存放路径,位于文件首行 */
if ((getline(&line, &n, fp)) == -1 || NULL == line || strlen(line) == 0)
{
ULOG_DEBUG(g_log_h, "File %s is empty", file_str);
goto END;
}
else
{
strncpy(ret_conf->path, line, strlen(line));
ret_conf->path[strlen(line)] = '\0';
/* 需要滤除掉行尾的换行符 */
if ('\n' == ret_conf->path[strlen(line)-1])
{
ret_conf->path[strlen(line)-1] = '\0';
}
}
/* 解析日志存放路径,位于文件首行 */
if ((getline(&line, &n, fp)) == -1 || NULL == line || strlen(line) == 0)
{
ULOG_DEBUG(g_log_h, "File %s is empty", file_str);
goto END;
}
else
{
strncpy(ret_conf->path, line, strlen(line));
ret_conf->path[strlen(line)] = '\0';
/* 需要滤除掉行尾的换行符 */
if ('\n' == ret_conf->path[strlen(line)-1])
{
ret_conf->path[strlen(line)-1] = '\0';
}
}
/* 跳过 “{” 行 */
if (getline(&line, &n, fp) == -1)
{
goto END;
}
/* 跳过 “{” 行 */
if (getline(&line, &n, fp) == -1)
{
goto END;
}
/* 解析日志存放最大天数 */
if ((getline(&line, &n, fp)) != -1)
{
pos = strstr(line, "rotate ");
if (NULL == pos)
{
goto END;
}
/* 解析日志存放最大天数 */
if ((getline(&line, &n, fp)) != -1)
{
pos = strstr(line, "rotate ");
if (NULL == pos)
{
goto END;
}
if (strlen(pos) == strlen("rotate "))
{
goto END;
}
if (strlen(pos) == strlen("rotate "))
{
goto END;
}
pos += strlen("rotate ");
/* 需要滤除掉行尾的换行符 */
if ('\n' == pos[strlen(pos)-1])
{
pos[strlen(pos)-1] = '\0';
}
ret_conf->del_over_days = (uint)atoi(pos);
}
else
{
goto END;
}
pos += strlen("rotate ");
/* 需要滤除掉行尾的换行符 */
if ('\n' == pos[strlen(pos)-1])
{
pos[strlen(pos)-1] = '\0';
}
ret_conf->del_over_days = (uint)atoi(pos);
}
else
{
goto END;
}
/* 跳过 “daily” 行 */
if (getline(&line, &n, fp) == -1)
{
goto END;
}
/* 跳过 missingok 行 */
if (getline(&line, &n, fp) == -1)
{
goto END;
}
/* 解析日志是否压缩 */
if ((getline(&line, &n, fp)) != -1)
{
if (NULL != strstr(line, "compress"))
{
ret_conf->is_compress = LOG_COMPRESS;
}
else
{
ret_conf->is_compress = LOG_UNCOMPRESS;
}
}
ret = RET_OK;
/* 跳过 “daily” 行 */
if (getline(&line, &n, fp) == -1)
{
goto END;
}
/* 跳过 missingok 行 */
if (getline(&line, &n, fp) == -1)
{
goto END;
}
/* 解析日志是否压缩 */
if ((getline(&line, &n, fp)) != -1)
{
if (NULL != strstr(line, "compress"))
{
ret_conf->is_compress = LOG_COMPRESS;
}
else
{
ret_conf->is_compress = LOG_UNCOMPRESS;
}
}
ret = RET_OK;
END:
if (NULL != line)
{
free(line);
}
if (NULL != fp)
{
fclose(fp);
}
return ret;
if (NULL != line)
{
free(line);
}
if (NULL != fp)
{
fclose(fp);
}
return ret;
}
static ret_code cm_get_log_file_elems(log_file_t *log_file_conf, int *err_no)
{
char value_str[MAX_LINE_SZ] = "";
u8 tmp_level = 6; /* INFO */
log_file_t tmp_file_conf = {0};
char value_str[MAX_LINE_SZ] = "";
u8 tmp_level = 6; /* INFO */
log_file_t tmp_file_conf = {0};
if (NULL == log_file_conf || NULL == err_no)
{
return RET_ERR;
}
if (NULL == log_file_conf || NULL == err_no)
{
return RET_ERR;
}
memset(log_file_conf, 0, sizeof(*log_file_conf));
/* 日志记录级别level */
if (cm_log_get_level_from_file(CM_LOG_CONF_LOGFILE_FILE, &tmp_level) == 0)
{
log_file_conf->level = tmp_level;
}
memset(log_file_conf, 0, sizeof(*log_file_conf));
/* 日志记录级别level */
if (cm_log_get_level_from_file(CM_LOG_CONF_LOGFILE_FILE, &tmp_level) == 0)
{
log_file_conf->level = tmp_level;
}
/* 日志记录路径path */
memset(value_str, 0, MAX_LINE_SZ);
if (cm_log_get_path_from_file(CM_LOG_CONF_LOGFILE_FILE, value_str, MAX_PATH_SZ) == 0)
{
memset(log_file_conf->path, 0, MAX_PATH_SZ);
strncpy(log_file_conf->path, value_str, strlen(value_str));
}
/* 日志记录路径path */
memset(value_str, 0, MAX_LINE_SZ);
if (cm_log_get_path_from_file(CM_LOG_CONF_LOGFILE_FILE, value_str, MAX_PATH_SZ) == 0)
{
memset(log_file_conf->path, 0, MAX_PATH_SZ);
strncpy(log_file_conf->path, value_str, strlen(value_str));
}
/* 日志文件是否压缩is_compress
* del_over_days */
if (cm_log_check_file_is_exist(CM_LOG_CONF_CONSOLE_FILE) == 1)
{
if (RET_OK == cm_log_get_logrotate_conf(CM_LOG_CONF_LOGROTATE_FILE, &tmp_file_conf))
{
log_file_conf->is_compress = tmp_file_conf.is_compress;
log_file_conf->del_over_days = tmp_file_conf.del_over_days;
}
}
/* 日志文件大小上限del_over_size */
memset(value_str, 0, MAX_LINE_SZ);
if (cm_log_get_keyvalue_from_file(CM_LOG_CONF_LOG_SCHED_FILE, LOG_CONF_KEY_FILE_MAX_SIZE_STR, value_str, sizeof(value_str)) == 0)
{
if (strlen(value_str) < MAX_U64_SZ)
{
memset(log_file_conf->del_over_size, 0, MAX_U64_SZ);
strncpy(log_file_conf->del_over_size, value_str, strlen(value_str));
}
}
/* 日志文件是否压缩is_compress
* del_over_days */
if (cm_log_check_file_is_exist(CM_LOG_CONF_CONSOLE_FILE) == 1)
{
if (RET_OK == cm_log_get_logrotate_conf(CM_LOG_CONF_LOGROTATE_FILE, &tmp_file_conf))
{
log_file_conf->is_compress = tmp_file_conf.is_compress;
log_file_conf->del_over_days = tmp_file_conf.del_over_days;
}
}
/* 日志文件大小上限del_over_size */
memset(value_str, 0, MAX_LINE_SZ);
if (cm_log_get_keyvalue_from_file(CM_LOG_CONF_LOG_SCHED_FILE, LOG_CONF_KEY_FILE_MAX_SIZE_STR, value_str, sizeof(value_str)) == 0)
{
if (strlen(value_str) < MAX_U64_SZ)
{
memset(log_file_conf->del_over_size, 0, MAX_U64_SZ);
strncpy(log_file_conf->del_over_size, value_str, strlen(value_str));
}
}
ULOG_DEBUG(g_log_h, "get log file del_over_size:%s", log_file_conf->del_over_size);
return RET_OK;
ULOG_DEBUG(g_log_h, "get log file del_over_size:%s", log_file_conf->del_over_size);
return RET_OK;
}
static ret_code cm_log_file_format_json(log_file_t *log_file_conf,
pointer output, int *outlen)
{
char *json_log_file = NULL;
char *json_log_file = NULL;
/* create Student JSON object */
s2j_create_json_obj(json_obj);
if (json_obj == NULL)
{
return RET_NOMEM;
}
/* create Student JSON object */
s2j_create_json_obj(json_obj);
if (json_obj == NULL)
{
return RET_NOMEM;
}
s2j_json_set_basic_element(json_obj, log_file_conf, int, level);
s2j_json_set_basic_element(json_obj, log_file_conf, string, path);
s2j_json_set_basic_element(json_obj, log_file_conf, int, is_compress);
s2j_json_set_basic_element(json_obj, log_file_conf, int, del_over_days);
s2j_json_set_basic_element(json_obj, log_file_conf, string, del_over_size);
s2j_json_set_basic_element(json_obj, log_file_conf, int, level);
s2j_json_set_basic_element(json_obj, log_file_conf, string, path);
s2j_json_set_basic_element(json_obj, log_file_conf, int, is_compress);
s2j_json_set_basic_element(json_obj, log_file_conf, int, del_over_days);
s2j_json_set_basic_element(json_obj, log_file_conf, string, del_over_size);
json_log_file = cJSON_PrintUnformatted(json_obj);
*outlen = strlen(json_log_file) + 1;
memcpy(output, json_log_file, *outlen);
json_log_file = cJSON_PrintUnformatted(json_obj);
*outlen = strlen(json_log_file) + 1;
memcpy(output, json_log_file, *outlen);
free(json_log_file);
s2j_delete_json_obj(json_obj);
free(json_log_file);
s2j_delete_json_obj(json_obj);
return RET_OK;
return RET_OK;
}
@ -237,32 +237,32 @@ ret_code log_file_config_get(uint source,
pointer input, int input_len,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
log_file_t *log_file_conf = NULL;
int err_no = 0;
log_file_conf = (log_file_t *)input;
ret_code ret = RET_OK;
log_file_t *log_file_conf = NULL;
int err_no = 0;
log_file_conf = (log_file_t *)input;
ret = cm_get_log_file_elems(log_file_conf, &err_no);
ret = cm_get_log_file_elems(log_file_conf, &err_no);
RET_ERR_FORMART(ret, err_no, output, *output_len);
ASSERT_RET(ret);
RET_ERR_FORMART(ret, err_no, output, *output_len);
ASSERT_RET(ret);
cm_log_file_format_json(log_file_conf, output, output_len);
cm_log_file_format_json(log_file_conf, output, output_len);
return ret;
return ret;
}
ret_code log_file_config_getall(uint source,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
log_file_t *log_file_conf = NULL;
ret_code ret = RET_OK;
log_file_t *log_file_conf = NULL;
log_file_conf = rpc_new(log_file_t, 1);
ret = log_file_config_get(source, (pointer)log_file_conf, sizeof(log_file_t)*1, output, output_len);
rpc_free(log_file_conf);
return ret;
log_file_conf = rpc_new(log_file_t, 1);
ret = log_file_config_get(source, (pointer)log_file_conf, sizeof(log_file_t)*1, output, output_len);
rpc_free(log_file_conf);
return ret;
}

View File

@ -19,102 +19,102 @@ ret_code log_monitor_config_proc(uint source, uint config_type,
static ret_code cm_get_log_monitor_elems(log_console_t *log_console_conf, int *err_no)
{
u8 tmp_level = 0;
if (NULL == log_console_conf || NULL == err_no)
{
return RET_ERR;
}
u8 tmp_level = 0;
if (NULL == log_console_conf || NULL == err_no)
{
return RET_ERR;
}
memset(log_console_conf, 0, sizeof(*log_console_conf));
memset(log_console_conf, 0, sizeof(*log_console_conf));
if (cm_log_check_file_is_exist(CM_LOG_CONF_PTY_FILE) != 1)
{
log_console_conf->on = LOG_OFF;
}
else
{
char tmp_module[MAX_MODULE_NAME_SZ] = "";
log_console_conf->on = LOG_ON;
memset(tmp_module, 0, MAX_MODULE_NAME_SZ);
if (cm_log_get_module_from_file(CM_LOG_CONF_PTY_FILE, tmp_module, MAX_MODULE_NAME_SZ) == 0)
{
strncpy(log_console_conf->module, tmp_module, MAX_MODULE_NAME_SZ);
}
if (cm_log_check_file_is_exist(CM_LOG_CONF_PTY_FILE) != 1)
{
log_console_conf->on = LOG_OFF;
}
else
{
char tmp_module[MAX_MODULE_NAME_SZ] = "";
log_console_conf->on = LOG_ON;
memset(tmp_module, 0, MAX_MODULE_NAME_SZ);
if (cm_log_get_module_from_file(CM_LOG_CONF_PTY_FILE, tmp_module, MAX_MODULE_NAME_SZ) == 0)
{
strncpy(log_console_conf->module, tmp_module, MAX_MODULE_NAME_SZ);
}
if (cm_log_get_level_from_file(CM_LOG_CONF_PTY_FILE, &tmp_level) == 0)
{
log_console_conf->level = tmp_level;
}
}
ULOG_DEBUG(g_log_h, "get log monitor :level=%u, is_on=%s, module=%s",
log_console_conf->level,
log_console_conf->on==LOG_ON?"on":"off",
log_console_conf->module);
return RET_OK;
if (cm_log_get_level_from_file(CM_LOG_CONF_PTY_FILE, &tmp_level) == 0)
{
log_console_conf->level = tmp_level;
}
}
ULOG_DEBUG(g_log_h, "get log monitor :level=%u, is_on=%s, module=%s",
log_console_conf->level,
log_console_conf->on==LOG_ON?"on":"off",
log_console_conf->module);
return RET_OK;
}
static ret_code cm_log_monitor_format_json(log_console_t *log_console_conf,
pointer output, int *outlen)
{
char *json_log_file = NULL;
char *json_log_file = NULL;
/* create Student JSON object */
s2j_create_json_obj(json_obj);
if (json_obj == NULL)
{
return RET_NOMEM;
}
/* create Student JSON object */
s2j_create_json_obj(json_obj);
if (json_obj == NULL)
{
return RET_NOMEM;
}
s2j_json_set_basic_element(json_obj, log_console_conf, int, level);
s2j_json_set_basic_element(json_obj, log_console_conf, int, on);
s2j_json_set_basic_element(json_obj, log_console_conf, string, module);
s2j_json_set_basic_element(json_obj, log_console_conf, int, level);
s2j_json_set_basic_element(json_obj, log_console_conf, int, on);
s2j_json_set_basic_element(json_obj, log_console_conf, string, module);
json_log_file = cJSON_PrintUnformatted(json_obj);
*outlen = strlen(json_log_file) + 1;
memcpy(output, json_log_file, *outlen);
json_log_file = cJSON_PrintUnformatted(json_obj);
*outlen = strlen(json_log_file) + 1;
memcpy(output, json_log_file, *outlen);
free(json_log_file);
cJSON_Delete(json_obj);
free(json_log_file);
cJSON_Delete(json_obj);
return RET_OK;
return RET_OK;
}
ret_code log_monitor_config_get(uint source,
pointer input, int input_len,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
log_console_t *log_console_conf = NULL;
int err_no = 0;
log_console_conf = (log_console_t *)input;
ret_code ret = RET_OK;
log_console_t *log_console_conf = NULL;
int err_no = 0;
log_console_conf = (log_console_t *)input;
ret = cm_get_log_monitor_elems(log_console_conf, &err_no);
ret = cm_get_log_monitor_elems(log_console_conf, &err_no);
RET_ERR_FORMART(ret, err_no, output, *output_len);
ASSERT_RET(ret);
RET_ERR_FORMART(ret, err_no, output, *output_len);
ASSERT_RET(ret);
cm_log_monitor_format_json(log_console_conf, output, output_len);
cm_log_monitor_format_json(log_console_conf, output, output_len);
return ret;
return ret;
}
ret_code log_monitor_config_getall(uint source,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
log_console_t *log_console_conf = NULL;
ret_code ret = RET_OK;
log_console_t *log_console_conf = NULL;
log_console_conf = rpc_new(log_console_t, 1);
ret = log_monitor_config_get(source, (pointer)log_console_conf, sizeof(log_console_t)*1, output, output_len);
rpc_free(log_console_conf);
return ret;
log_console_conf = rpc_new(log_console_t, 1);
ret = log_monitor_config_get(source, (pointer)log_console_conf, sizeof(log_console_t)*1, output, output_len);
rpc_free(log_console_conf);
return ret;
}

View File

@ -64,482 +64,482 @@ ret_code log_remote_level_config_proc(uint source, uint config_type,
static ret_code cm_get_log_remote_level_elems(log_remote_level_t *log_remote_level, int *err_no)
{
char value[MAX_LINE_SZ] = "";
char value[MAX_LINE_SZ] = "";
if (NULL == log_remote_level || NULL == err_no)
{
return RET_ERR;
}
if (NULL == log_remote_level || NULL == err_no)
{
return RET_ERR;
}
memset(log_remote_level, 0, sizeof(*log_remote_level));
memset(log_remote_level, 0, sizeof(*log_remote_level));
memset(value, 0, MAX_LINE_SZ);
if (cm_log_get_keyvalue_from_file(CM_LOG_CONF_REMOTE_LEVEL_FILE, LOG_CONF_KEY_REMOTE_LEVEL, value, sizeof(value)) == 0)
{
int tmp_value = atoi(value);
log_remote_level->level = (u8)tmp_value;
}
memset(value, 0, MAX_LINE_SZ);
if (cm_log_get_keyvalue_from_file(CM_LOG_CONF_REMOTE_LEVEL_FILE, LOG_CONF_KEY_REMOTE_LEVEL, value, sizeof(value)) == 0)
{
int tmp_value = atoi(value);
log_remote_level->level = (u8)tmp_value;
}
ULOG_DEBUG(g_log_h, "get log remote level:%u", log_remote_level->level);
return RET_OK;
ULOG_DEBUG(g_log_h, "get log remote level:%u", log_remote_level->level);
return RET_OK;
}
static ret_code cm_log_remote_level_format_json(log_remote_level_t *log_remote_level,
pointer output, int *outlen)
{
char *json_log_file = NULL;
char *json_log_file = NULL;
/* create Student JSON object */
s2j_create_json_obj(json_obj);
if (json_obj == NULL)
{
return RET_NOMEM;
}
/* create Student JSON object */
s2j_create_json_obj(json_obj);
if (json_obj == NULL)
{
return RET_NOMEM;
}
s2j_json_set_basic_element(json_obj, log_remote_level, int, level);
s2j_json_set_basic_element(json_obj, log_remote_level, int, level);
json_log_file = cJSON_PrintUnformatted(json_obj);
*outlen = strlen(json_log_file) + 1;
memcpy(output, json_log_file, *outlen);
json_log_file = cJSON_PrintUnformatted(json_obj);
*outlen = strlen(json_log_file) + 1;
memcpy(output, json_log_file, *outlen);
free(json_log_file);
cJSON_Delete(json_obj);
free(json_log_file);
cJSON_Delete(json_obj);
return RET_OK;
return RET_OK;
}
ret_code log_remote_level_config_get(uint source,
pointer input, int input_len,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
log_remote_level_t *log_remote_level = NULL;
int err_no = 0;
log_remote_level = (log_remote_level_t *)input;
ret_code ret = RET_OK;
log_remote_level_t *log_remote_level = NULL;
int err_no = 0;
log_remote_level = (log_remote_level_t *)input;
ret = cm_get_log_remote_level_elems(log_remote_level, &err_no);
ret = cm_get_log_remote_level_elems(log_remote_level, &err_no);
RET_ERR_FORMART(ret, err_no, output, *output_len);
ASSERT_RET(ret);
RET_ERR_FORMART(ret, err_no, output, *output_len);
ASSERT_RET(ret);
cm_log_remote_level_format_json(log_remote_level, output, output_len);
cm_log_remote_level_format_json(log_remote_level, output, output_len);
return ret;
return ret;
}
ret_code log_remote_level_config_getall(uint source,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
ret_code ret = RET_OK;
log_remote_level_t *log_remote_level = NULL;
log_remote_level = rpc_new(log_remote_level_t, 1);
ret = log_remote_level_config_get(source, (pointer)log_remote_level, sizeof(log_remote_level_t)*1, output, output_len);
rpc_free(log_remote_level);
return ret;
log_remote_level = rpc_new(log_remote_level_t, 1);
ret = log_remote_level_config_get(source, (pointer)log_remote_level, sizeof(log_remote_level_t)*1, output, output_len);
rpc_free(log_remote_level);
return ret;
}
/* *.=emerg;*.=alert;*.=crit;*.=err;*.=warn;*.=notice;*.=info @1.1.1.1:514;RFC3164fmt
* *.=emerg;*.=alert;*.=crit;*.=err;*.=warn;*.=notice;*.=info @@1.1.1.2:514;RFC5424fmt */
static ret_code cm_log_prase_host_from_str(char *const input_str, log_remote_host_x_t *ret_host)
{
char *pos = NULL;
char *pos2 = NULL;
size_t tmp_len = 0;
char tmp_str[128] = "";
int tmp_value;
int is_find = 0;
ret_code ret = RET_ERR;
char *pos = NULL;
char *pos2 = NULL;
size_t tmp_len = 0;
char tmp_str[128] = "";
int tmp_value;
int is_find = 0;
ret_code ret = RET_ERR;
if(NULL == input_str || '\0' == input_str[0] || NULL == ret_host)
{
return RET_ERR;
}
if(NULL == input_str || '\0' == input_str[0] || NULL == ret_host)
{
return RET_ERR;
}
pos = input_str;
pos = input_str;
memset(tmp_str, 0, sizeof(tmp_str));
memset(tmp_str, 0, sizeof(tmp_str));
/* 提取日志等级 */
while (1)
{
pos2 = strstr(pos, ".=");
if (NULL == pos2)
{
break;
}
if (strlen(pos2) <= strlen(".="))
{
break;
}
pos = pos2+strlen(".=");
}
/* 提取日志等级 */
while (1)
{
pos2 = strstr(pos, ".=");
if (NULL == pos2)
{
break;
}
if (strlen(pos2) <= strlen(".="))
{
break;
}
pos = pos2+strlen(".=");
}
if (NULL == pos)
{
goto END;
}
pos2 = strstr(pos, " ");
if (NULL == pos2)
{
goto END;
}
tmp_len = pos2-pos;
strncpy(tmp_str, pos, tmp_len);
tmp_str[tmp_len] = '\0';
if (NULL == pos)
{
goto END;
}
pos2 = strstr(pos, " ");
if (NULL == pos2)
{
goto END;
}
tmp_len = pos2-pos;
strncpy(tmp_str, pos, tmp_len);
tmp_str[tmp_len] = '\0';
tmp_value = log_str_to_level(tmp_str);
if ( -1 == tmp_value)
{
goto END;
}
ret_host->level = (u8)tmp_value;
tmp_value = log_str_to_level(tmp_str);
if ( -1 == tmp_value)
{
goto END;
}
ret_host->level = (u8)tmp_value;
/* 提取IP地址 */
pos = strstr(pos2, "@");
if (NULL == pos)
{
goto END;
}
pos ++;
/* 提取IP地址 */
pos = strstr(pos2, "@");
if (NULL == pos)
{
goto END;
}
pos ++;
if('@' == pos[0])
{
pos++;
}
if('@' == pos[0])
{
pos++;
}
pos2 = strstr(pos, ":");
if (NULL == pos2)
{
goto END;
}
pos2 = strstr(pos, ":");
if (NULL == pos2)
{
goto END;
}
tmp_len = pos2-pos;
if (tmp_len == 0 || tmp_len >= sizeof(ret_host->host))
{
goto END;
}
memset(ret_host->host, 0, sizeof(ret_host->host));
strncpy(ret_host->host, pos, tmp_len);
tmp_len = pos2-pos;
if (tmp_len == 0 || tmp_len >= sizeof(ret_host->host))
{
goto END;
}
memset(ret_host->host, 0, sizeof(ret_host->host));
strncpy(ret_host->host, pos, tmp_len);
/* 提取端口 */
pos2 ++;
pos = pos2;
pos2 = strstr(pos, ";");
if (pos2 == NULL)
{
goto END;
}
tmp_len = pos2-pos;
strncpy(tmp_str, pos, tmp_len);
tmp_str[tmp_len] = '\0';
/* 提取端口 */
pos2 ++;
pos = pos2;
pos2 = strstr(pos, ";");
if (pos2 == NULL)
{
goto END;
}
tmp_len = pos2-pos;
strncpy(tmp_str, pos, tmp_len);
tmp_str[tmp_len] = '\0';
tmp_value = atoi(tmp_str);
if (tmp_value < 0)
{
goto END;
}
ret_host->port = (u16)tmp_value;
tmp_value = atoi(tmp_str);
if (tmp_value < 0)
{
goto END;
}
ret_host->port = (u16)tmp_value;
/* 提取日志存放格式 */
pos2++;
pos = pos2;
pos2 = strstr(pos, " ");
if (pos2 != NULL)
{
tmp_len = pos2-pos;
}
else
{
tmp_len = strlen(pos);
}
strncpy(tmp_str, pos, tmp_len);
tmp_str[tmp_len] = '\0';
if ('\n' == tmp_str[tmp_len-1])
{
tmp_str[tmp_len-1] = '\0';
}
/* 提取日志存放格式 */
pos2++;
pos = pos2;
pos2 = strstr(pos, " ");
if (pos2 != NULL)
{
tmp_len = pos2-pos;
}
else
{
tmp_len = strlen(pos);
}
strncpy(tmp_str, pos, tmp_len);
tmp_str[tmp_len] = '\0';
if ('\n' == tmp_str[tmp_len-1])
{
tmp_str[tmp_len-1] = '\0';
}
tmp_value = -1;
for (int i = 0; i < (sizeof(rfc_tbl) / sizeof(rfc_key_fmt)); i++)
{
if (strcasecmp(tmp_str, rfc_tbl[i].fmt) == 0)
{
tmp_value = rfc_tbl[i].rfc;
break;
}
}
tmp_value = -1;
for (int i = 0; i < (sizeof(rfc_tbl) / sizeof(rfc_key_fmt)); i++)
{
if (strcasecmp(tmp_str, rfc_tbl[i].fmt) == 0)
{
tmp_value = rfc_tbl[i].rfc;
break;
}
}
if (-1 == tmp_value)
{
goto END;
}
ret_host->rfc = tmp_value;
if (-1 == tmp_value)
{
goto END;
}
ret_host->rfc = tmp_value;
// ULOG_DEBUG(g_log_h, "get remote host, addr:%s, port:%u, log_format:%d, level:%u",
// ret_host->host, ret_host->port, ret_host->rfc, ret_host->level);
// ULOG_DEBUG(g_log_h, "get remote host, addr:%s, port:%u, log_format:%d, level:%u",
// ret_host->host, ret_host->port, ret_host->rfc, ret_host->level);
is_find = 1;
is_find = 1;
END:
if (is_find != 1)
{
memset(ret_host, 0, sizeof(*ret_host));
}
if (is_find != 1)
{
memset(ret_host, 0, sizeof(*ret_host));
}
ret = RET_OK;
return ret;
ret = RET_OK;
return ret;
}
/* 传入的过滤条件必须有IP址址可以仅IP地址过滤可以IP地址+其它条件组合过滤
* */
static ret_code cm_log_get_host_from_file_by_detail(const char *file_str,
const log_remote_host_x_t *input_host,
log_remote_host_x_t *ret_hosts,
int *ret_cnt)
const log_remote_host_x_t *input_host,
log_remote_host_x_t *ret_hosts,
int *ret_cnt)
{
log_remote_host_x_t hosts[MAX_REMOTE_HOST_CNT];
FILE *fp = NULL;
ssize_t n;
char *line = NULL;
char tmp_str[128] = "";
int cnt = 0;
ret_code ret = RET_ERR;
log_remote_host_x_t hosts[MAX_REMOTE_HOST_CNT];
FILE *fp = NULL;
ssize_t n;
char *line = NULL;
char tmp_str[128] = "";
int cnt = 0;
ret_code ret = RET_ERR;
if (NULL == file_str || '\0' == file_str[0]
|| NULL == input_host || '\0' == input_host->host[0]
|| NULL == ret_hosts
|| NULL == ret_cnt) {
ULOG_ERR(g_log_h, "get log host from file: bad input");
}
if (NULL == file_str || '\0' == file_str[0]
|| NULL == input_host || '\0' == input_host->host[0]
|| NULL == ret_hosts
|| NULL == ret_cnt) {
ULOG_ERR(g_log_h, "get log host from file: bad input");
}
memset(hosts, 0, sizeof(hosts));
memset(hosts, 0, sizeof(hosts));
fp = fopen(file_str, "r");
if (NULL == fp) {
return ret;
}
fp = fopen(file_str, "r");
if (NULL == fp) {
return ret;
}
if (fseek(fp, 0, SEEK_SET) == -1)
{
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
fclose(fp);
return ret;
}
if (fseek(fp, 0, SEEK_SET) == -1)
{
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
fclose(fp);
return ret;
}
memset(tmp_str, 0, sizeof(tmp_str));
sprintf(tmp_str, "@%s:", input_host->host);
memset(tmp_str, 0, sizeof(tmp_str));
sprintf(tmp_str, "@%s:", input_host->host);
cnt = 0;
while ((getline(&line, &n, fp)) != -1)
{
memset(&hosts[cnt], 0, sizeof(log_remote_host_x_t));
cnt = 0;
while ((getline(&line, &n, fp)) != -1)
{
memset(&hosts[cnt], 0, sizeof(log_remote_host_x_t));
/* IP地址匹配 */
if (NULL == strstr(line, tmp_str))
{
continue;
}
if ( cm_log_prase_host_from_str(line, hosts+cnt) == RET_OK )
{
/* 端口匹配 */
if (input_host->port > 0 && input_host->port != hosts[cnt].port)
{
continue;
}
/* IP地址匹配 */
if (NULL == strstr(line, tmp_str))
{
continue;
}
if ( cm_log_prase_host_from_str(line, hosts+cnt) == RET_OK )
{
/* 端口匹配 */
if (input_host->port > 0 && input_host->port != hosts[cnt].port)
{
continue;
}
/* 日志标准匹配 */
if (input_host->rfc != LOG_RFC_UNKNOWN && input_host->rfc != hosts[cnt].rfc)
{
continue;
}
}
/* 日志标准匹配 */
if (input_host->rfc != LOG_RFC_UNKNOWN && input_host->rfc != hosts[cnt].rfc)
{
continue;
}
}
ULOG_DEBUG(g_log_h, "get remote host, host[%d]: addr=%s, port=%u, log_format=%d, level=%u",
cnt, hosts[cnt].host, hosts[cnt].port, hosts[cnt].rfc, hosts[cnt].level);
cnt++;
if (cnt >= MAX_REMOTE_HOST_CNT)
{
break;
}
ULOG_DEBUG(g_log_h, "get remote host, host[%d]: addr=%s, port=%u, log_format=%d, level=%u",
cnt, hosts[cnt].host, hosts[cnt].port, hosts[cnt].rfc, hosts[cnt].level);
cnt++;
if (cnt >= MAX_REMOTE_HOST_CNT)
{
break;
}
}
}
if (cnt > 0)
{
memcpy(ret_hosts, &hosts, sizeof(log_remote_host_x_t)*cnt);
}
*ret_cnt = cnt;
if (cnt > 0)
{
memcpy(ret_hosts, &hosts, sizeof(log_remote_host_x_t)*cnt);
}
*ret_cnt = cnt;
if (NULL != line)
{
free(line);
}
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
return ret;
if (NULL != line)
{
free(line);
}
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
return ret;
}
static ret_code cm_log_getall_host_from_file(const char *file_str, log_remote_host_x_t *ret_hosts, int *ret_cnt)
{
log_remote_host_x_t hosts[MAX_REMOTE_HOST_CNT];
FILE *fp = NULL;
ssize_t n;
char *line = NULL;
size_t tmp_len = 0;
char tmp_str[128] = "";
int cnt = 0;
ret_code ret = RET_ERR;
log_remote_host_x_t hosts[MAX_REMOTE_HOST_CNT];
FILE *fp = NULL;
ssize_t n;
char *line = NULL;
size_t tmp_len = 0;
char tmp_str[128] = "";
int cnt = 0;
ret_code ret = RET_ERR;
if (NULL == file_str || '\0' == file_str[0]
|| NULL == ret_hosts || NULL == ret_cnt)
{
ULOG_ERR(g_log_h, "get all log host from file: bad input");
}
if (NULL == file_str || '\0' == file_str[0]
|| NULL == ret_hosts || NULL == ret_cnt)
{
ULOG_ERR(g_log_h, "get all log host from file: bad input");
}
fp = fopen(file_str, "r");
if (NULL == fp)
{
return ret;
}
fp = fopen(file_str, "r");
if (NULL == fp)
{
return ret;
}
if (fseek(fp, 0, SEEK_SET) == -1)
{
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
fclose(fp);
return ret;
}
if (fseek(fp, 0, SEEK_SET) == -1)
{
ULOG_ERR(g_log_h, "Seeknig config to begin is faiure:%s", strerror(errno));
fclose(fp);
return ret;
}
cnt = 0;
while ((getline(&line, &n, fp)) != -1)
{
if (NULL == strstr(line, "@"))
{
continue;
}
cnt = 0;
while ((getline(&line, &n, fp)) != -1)
{
if (NULL == strstr(line, "@"))
{
continue;
}
if ( cm_log_prase_host_from_str(line, hosts+cnt) != RET_OK )
{
continue;
}
if ( cm_log_prase_host_from_str(line, hosts+cnt) != RET_OK )
{
continue;
}
if ('\0' == hosts[cnt].host[0])
{
/* 无效数据 */
memset(hosts+cnt, 0, sizeof(log_remote_host_x_t));
continue;
}
ULOG_DEBUG(g_log_h, "getall remote host, host[%d]: addr=%s, port=%u, log_format=%d, level=%u",
cnt, hosts[cnt].host, hosts[cnt].port, hosts[cnt].rfc, hosts[cnt].level);
if ('\0' == hosts[cnt].host[0])
{
/* 无效数据 */
memset(hosts+cnt, 0, sizeof(log_remote_host_x_t));
continue;
}
ULOG_DEBUG(g_log_h, "getall remote host, host[%d]: addr=%s, port=%u, log_format=%d, level=%u",
cnt, hosts[cnt].host, hosts[cnt].port, hosts[cnt].rfc, hosts[cnt].level);
cnt ++;
if (cnt >= MAX_REMOTE_HOST_CNT)
{
break;
}
}
cnt ++;
if (cnt >= MAX_REMOTE_HOST_CNT)
{
break;
}
}
if (cnt > 0)
{
memcpy(ret_hosts, &hosts, sizeof(log_remote_host_x_t)*cnt);
}
if (cnt > 0)
{
memcpy(ret_hosts, &hosts, sizeof(log_remote_host_x_t)*cnt);
}
*ret_cnt = cnt;
*ret_cnt = cnt;
if (NULL != line)
{
free(line);
}
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
return ret;
if (NULL != line)
{
free(line);
}
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
return ret;
}
static ret_code cm_get_log_remote_host_elems(log_remote_host_x_t *input_host, log_remote_host_x_t *ret_hosts, int *cnt, int *err_no)
{
if (NULL == input_host || NULL == ret_hosts || NULL == cnt)
{
return RET_ERR;
}
if (cm_log_get_host_from_file_by_detail(CM_LOG_CONF_REMOTE_FILE, input_host, ret_hosts, cnt) != RET_OK)
{
return RET_ERR;
}
return RET_OK;
if (NULL == input_host || NULL == ret_hosts || NULL == cnt)
{
return RET_ERR;
}
if (cm_log_get_host_from_file_by_detail(CM_LOG_CONF_REMOTE_FILE, input_host, ret_hosts, cnt) != RET_OK)
{
return RET_ERR;
}
return RET_OK;
}
static ret_code cm_getall_log_remote_host_elems(log_remote_host_x_t *ret_hosts, int *cnt, int *err_no)
{
if (NULL == ret_hosts || NULL == cnt)
{
return RET_ERR;
}
if (NULL == ret_hosts || NULL == cnt)
{
return RET_ERR;
}
if (cm_log_getall_host_from_file(CM_LOG_CONF_REMOTE_FILE, ret_hosts, cnt) != RET_OK)
{
return RET_ERR;
}
return RET_OK;
if (cm_log_getall_host_from_file(CM_LOG_CONF_REMOTE_FILE, ret_hosts, cnt) != RET_OK)
{
return RET_ERR;
}
return RET_OK;
}
static ret_code cm_log_remote_host_x_format_json(log_remote_host_x_t *host_x,
pointer output, int *outlen)
{
char *json_log_file = NULL;
char *json_log_file = NULL;
/* create Student JSON object */
s2j_create_json_obj(json_obj);
if (json_obj == NULL)
{
return RET_NOMEM;
}
s2j_json_set_basic_element(json_obj, host_x, int, port);
/* create Student JSON object */
s2j_create_json_obj(json_obj);
if (json_obj == NULL)
{
return RET_NOMEM;
}
s2j_json_set_basic_element(json_obj, host_x, int, port);
s2j_json_set_basic_element(json_obj, host_x, int, rfc);
s2j_json_set_basic_element(json_obj, host_x, string, host);
s2j_json_set_basic_element(json_obj, host_x, int, level);
s2j_json_set_basic_element(json_obj, host_x, int, level);
json_log_file = cJSON_PrintUnformatted(json_obj);
*outlen = strlen(json_log_file) + 1;
memcpy(output, json_log_file, *outlen);
json_log_file = cJSON_PrintUnformatted(json_obj);
*outlen = strlen(json_log_file) + 1;
memcpy(output, json_log_file, *outlen);
free(json_log_file);
cJSON_Delete(json_obj);
free(json_log_file);
cJSON_Delete(json_obj);
return RET_OK;
return RET_OK;
}
@ -560,7 +560,7 @@ ret_code cm_log_remote_host_x_format_json_array(log_remote_host_x_t *host_xs,
for(i = 0; i < count; i++)
{
memcpy(host_x, &host_xs[i], sizeof(log_remote_host_x_t));
memcpy(host_x, &host_xs[i], sizeof(log_remote_host_x_t));
/* create Student JSON object */
s2j_create_json_obj(json_obj);
@ -571,10 +571,10 @@ ret_code cm_log_remote_host_x_format_json_array(log_remote_host_x_t *host_xs,
cJSON_AddItemToArray(json_array, json_obj);
s2j_json_set_basic_element(json_obj, host_x, int, port);
s2j_json_set_basic_element(json_obj, host_x, int, rfc);
s2j_json_set_basic_element(json_obj, host_x, string, host);
s2j_json_set_basic_element(json_obj, host_x, int, level);
s2j_json_set_basic_element(json_obj, host_x, int, port);
s2j_json_set_basic_element(json_obj, host_x, int, rfc);
s2j_json_set_basic_element(json_obj, host_x, string, host);
s2j_json_set_basic_element(json_obj, host_x, int, level);
}
json_str = cJSON_PrintUnformatted(json_array);
@ -599,52 +599,52 @@ ret_code log_remote_host_x_config_get(uint source,
pointer input, int input_len,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
log_remote_host_x_t *host_xs = NULL;
int cnt = 0;
int err_no = 0;
host_xs = rpc_new(log_remote_host_x_t, MAX_REMOTE_HOST_CNT);
if (NULL == host_xs)
{
return RET_NOMEM;
}
ret_code ret = RET_OK;
log_remote_host_x_t *host_xs = NULL;
int cnt = 0;
int err_no = 0;
host_xs = rpc_new(log_remote_host_x_t, MAX_REMOTE_HOST_CNT);
if (NULL == host_xs)
{
return RET_NOMEM;
}
ret = cm_get_log_remote_host_elems((log_remote_host_x_t *)input, host_xs, &cnt, &err_no);
ret = cm_get_log_remote_host_elems((log_remote_host_x_t *)input, host_xs, &cnt, &err_no);
RET_ERR_FORMART(ret, err_no, output, *output_len);
ASSERT_RET(ret);
RET_ERR_FORMART(ret, err_no, output, *output_len);
ASSERT_RET(ret);
cm_log_remote_host_x_format_json_array(host_xs, cnt, output, output_len);
rpc_free(host_xs);
cm_log_remote_host_x_format_json_array(host_xs, cnt, output, output_len);
rpc_free(host_xs);
return ret;
return ret;
}
ret_code log_remote_host_x_config_getall(uint source,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
log_remote_host_x_t *host_xs = NULL;
int cnt = 0;
int err_no = 0;
ret_code ret = RET_OK;
log_remote_host_x_t *host_xs = NULL;
int cnt = 0;
int err_no = 0;
host_xs = rpc_new(log_remote_host_x_t, MAX_REMOTE_HOST_CNT);
if (NULL == host_xs)
{
return RET_NOMEM;
}
host_xs = rpc_new(log_remote_host_x_t, MAX_REMOTE_HOST_CNT);
if (NULL == host_xs)
{
return RET_NOMEM;
}
ret = cm_getall_log_remote_host_elems(host_xs, &cnt, &err_no);
ret = cm_getall_log_remote_host_elems(host_xs, &cnt, &err_no);
RET_ERR_FORMART(ret, err_no, output, *output_len);
ASSERT_RET(ret);
RET_ERR_FORMART(ret, err_no, output, *output_len);
ASSERT_RET(ret);
cm_log_remote_host_x_format_json_array(host_xs, cnt, output, output_len);
rpc_free(host_xs);
return ret;
cm_log_remote_host_x_format_json_array(host_xs, cnt, output, output_len);
rpc_free(host_xs);
return ret;
}

View File

@ -11,57 +11,57 @@ static int logging_file_json_parse(pointer input, log_file_t *config_buff);
int conf_file(cJSON *json_obj, int argc, char **argv)
{
{
log_file_t log_file = {0};
log_file_t log_file_out = {0};
log_file_t log_file_out = {0};
int level = LOG_INFO;
uint config_type = CM_CONFIG_SET;
char *json_output = NULL;
uint config_type = CM_CONFIG_SET;
char *json_output = NULL;
log_file.is_compress = LOG_UNCOMPRESS;
if (argc == 3 && strstr(argv[2], "get") != NULL)
{
config_type = CM_CONFIG_GET;
}
else
{
config_type = CM_CONFIG_SET;
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 == 3 && strstr(argv[2], "get") != NULL)
{
config_type = CM_CONFIG_GET;
}
else
{
config_type = CM_CONFIG_SET;
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 >= 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 >= 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;
}
}
}
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);
@ -76,12 +76,12 @@ int conf_file(cJSON *json_obj, int argc, char **argv)
ULOG_DEBUG(g_log, "File log whice is configured is success");
}
if (CM_CONFIG_GET == config_type)
{
logging_file_json_parse(json_output, &log_file_out);
if (CM_CONFIG_GET == config_type)
{
logging_file_json_parse(json_output, &log_file_out);
logging_get_file_print(&log_file_out);
}
logging_get_file_print(&log_file_out);
}
return ret;
}
@ -89,62 +89,62 @@ int conf_file(cJSON *json_obj, int argc, char **argv)
static int logging_file_json_parse(pointer input, log_file_t *config_buff)
{
cJSON *json_obj;
cJSON *json_obj;
if (NULL == config_buff)
{
return -1;
}
if (NULL == config_buff)
{
return -1;
}
json_obj = cJSON_Parse(input);
if (!json_obj)
{
return -1;
}
json_obj = cJSON_Parse(input);
if (!json_obj)
{
return -1;
}
s2j_create_struct_obj(log_file, log_file_t);
if (log_file == NULL)
{
cJSON_Delete(json_obj);
return -1;
}
s2j_create_struct_obj(log_file, log_file_t);
if (log_file == NULL)
{
cJSON_Delete(json_obj);
return -1;
}
s2j_struct_get_basic_element(log_file, json_obj, int, level);
S2J_STRUCT_GET_STRING_ELEMENT_N(log_file, json_obj, path, MAX_PATH_SZ);
s2j_struct_get_basic_element(log_file, json_obj, int, is_compress);
s2j_struct_get_basic_element(log_file, json_obj, int, del_over_days);
S2J_STRUCT_GET_STRING_ELEMENT_N(log_file, json_obj, del_over_size, MAX_U64_SZ);
s2j_struct_get_basic_element(log_file, json_obj, int, level);
S2J_STRUCT_GET_STRING_ELEMENT_N(log_file, json_obj, path, MAX_PATH_SZ);
s2j_struct_get_basic_element(log_file, json_obj, int, is_compress);
s2j_struct_get_basic_element(log_file, json_obj, int, del_over_days);
S2J_STRUCT_GET_STRING_ELEMENT_N(log_file, json_obj, del_over_size, MAX_U64_SZ);
memcpy(config_buff, log_file, sizeof(log_file_t));
s2j_delete_struct_obj(log_file);
cJSON_Delete(json_obj);
memcpy(config_buff, log_file, sizeof(log_file_t));
return RET_OK;
s2j_delete_struct_obj(log_file);
cJSON_Delete(json_obj);
return RET_OK;
}
void logging_get_file_print(log_file_t *log_conf)
{
if (NULL == log_conf)
{
return;
}
fprintf(stdout, "--------------------------------------------------------------------------------\n");
fprintf(stdout, " get file:\n\n");
if (log_conf->level < sizeof(g_level_array) / sizeof(level_str_t))
fprintf(stdout, " level %s\n", g_level_array[log_conf->level].str);
else
fprintf(stdout, " level <invalid_value>\n");
fprintf(stdout, " file_path %s\n", log_conf->path);
fprintf(stdout, " is_compress %s\n", log_conf->is_compress==LOG_UNCOMPRESS?"no":"yes");
fprintf(stdout, " del_over_days %u\n", log_conf->del_over_days);
fprintf(stdout, " del_over_size %s\n", log_conf->del_over_size);
fprintf(stdout, "--------------------------------------------------------------------------------\n");
if (NULL == log_conf)
{
return;
}
ULOG_DEBUG(g_log, "Log file get: level=%u, path=%s, is_compress=%d, del_over_days=%u, del_over_size=%s",
log_conf->level,
log_conf->path,
log_conf->is_compress,
log_conf->del_over_days, log_conf->del_over_size);
fprintf(stdout, "--------------------------------------------------------------------------------\n");
fprintf(stdout, " get file:\n\n");
if (log_conf->level < sizeof(g_level_array) / sizeof(level_str_t))
fprintf(stdout, " level %s\n", g_level_array[log_conf->level].str);
else
fprintf(stdout, " level <invalid_value>\n");
fprintf(stdout, " file_path %s\n", log_conf->path);
fprintf(stdout, " is_compress %s\n", log_conf->is_compress==LOG_UNCOMPRESS?"no":"yes");
fprintf(stdout, " del_over_days %u\n", log_conf->del_over_days);
fprintf(stdout, " del_over_size %s\n", log_conf->del_over_size);
fprintf(stdout, "--------------------------------------------------------------------------------\n");
ULOG_DEBUG(g_log, "Log file get: level=%u, path=%s, is_compress=%d, del_over_days=%u, del_over_size=%s",
log_conf->level,
log_conf->path,
log_conf->is_compress,
log_conf->del_over_days, log_conf->del_over_size);
}

View File

@ -28,37 +28,37 @@ static log_rfc_t get_rfc_by_name(const char *name)
}
static int conf_remote_by_config_id(cJSON *json_obj, const char *host, const u16 port, const log_rfc_t rfc, uint64 config_id)
{
{
log_remote_host_x_t remote = {0};
char *json_output = NULL;
int config_type = CM_CONFIG_SET;
char *json_output = NULL;
int config_type = CM_CONFIG_SET;
if (LOG_CONFIG_REMOTE_GET_HOST == config_id)
{
if (NULL == host || '\0' == host[0])
{
config_type = CM_CONFIG_GET_ALL;
}
else
{
config_type = CM_CONFIG_GET;
strncpy(remote.host, host, sizeof(remote.host));
}
remote.port = port;
remote.rfc = rfc;
}
else
{
config_type = CM_CONFIG_SET;
strncpy(remote.host, host, sizeof(remote.host));
remote.port = port;
remote.rfc = rfc;
}
if (LOG_CONFIG_REMOTE_GET_HOST == config_id)
{
if (NULL == host || '\0' == host[0])
{
config_type = CM_CONFIG_GET_ALL;
}
else
{
config_type = CM_CONFIG_GET;
strncpy(remote.host, host, sizeof(remote.host));
}
remote.port = port;
remote.rfc = rfc;
}
else
{
config_type = CM_CONFIG_SET;
strncpy(remote.host, host, sizeof(remote.host));
remote.port = port;
remote.rfc = rfc;
}
s2j_json_set_basic_element(json_obj, &remote, int, port);
s2j_json_set_basic_element(json_obj, &remote, int, rfc);
s2j_json_set_basic_element(json_obj, &remote, string, host);
s2j_json_set_basic_element(json_obj, &remote, int, level);
s2j_json_set_basic_element(json_obj, &remote, int, level);
int ret = set_log_conf(config_type, json_obj, config_id, &json_output);
if (ret != 0) {
@ -67,20 +67,19 @@ static int conf_remote_by_config_id(cJSON *json_obj, const char *host, const u16
ULOG_DEBUG(g_log, "Host of log whice is configured is success");
}
if (LOG_CONFIG_REMOTE_GET_HOST == config_id)
{
/* getÓëgetallͬÑùÊÊºÏ */
log_remote_host_x_t remotes_out[MAX_REMOTE_HOST_CNT] = {0};
int cnt = 0;
if (logging_remote_json_parse_array(json_output, remotes_out, &cnt) == 0)
{
logging_get_remote_print(remotes_out, cnt);
}
}
if (LOG_CONFIG_REMOTE_GET_HOST == config_id)
{
/* get与getall同样适合 */
log_remote_host_x_t remotes_out[MAX_REMOTE_HOST_CNT] = {0};
int cnt = 0;
if (logging_remote_json_parse_array(json_output, remotes_out, &cnt) == 0)
{
logging_get_remote_print(remotes_out, cnt);
}
}
return ret;
}
}
int conf_remote(cJSON *json_obj, int argc, char **argv)
{
@ -97,7 +96,7 @@ int conf_remote(cJSON *json_obj, int argc, char **argv)
} else if (strcasecmp(argv[2], "del") == 0) {
config_id = LOG_CONFIG_REMOTE_DEL_HOST;
} else if (strcasecmp(argv[2], "get") == 0
|| strcasecmp(argv[2], "getall") == 0) {
|| strcasecmp(argv[2], "getall") == 0) {
config_id = LOG_CONFIG_REMOTE_GET_HOST;
} else {
ULOG_WARNING(g_log, "Unknown operation command:%s", argv[2]);
@ -105,22 +104,22 @@ int conf_remote(cJSON *json_obj, int argc, char **argv)
}
char *host = NULL;
if (argc >= 4) {
host = argv[3];
}
if (argc >= 4) {
host = argv[3];
}
u16 port = DEFAULT_REMOTE_HOST_PORT;
if (LOG_CONFIG_REMOTE_GET_HOST == config_id) {
port = 0;
}
if (LOG_CONFIG_REMOTE_GET_HOST == config_id) {
port = 0;
}
if (argc >= 5) {
port= atoi(argv[4]);
}
log_rfc_t rfc = LOG_RFC_3164;
if (LOG_CONFIG_REMOTE_GET_HOST == config_id) {
rfc = LOG_RFC_UNKNOWN;
}
if (LOG_CONFIG_REMOTE_GET_HOST == config_id) {
rfc = LOG_RFC_UNKNOWN;
}
if (argc >= 6) {
rfc = get_rfc_by_name(argv[5]);
if (rfc == LOG_RFC_UNKNOWN) {
@ -133,30 +132,30 @@ int conf_remote(cJSON *json_obj, int argc, char **argv)
int conf_remote_level(cJSON *json_obj, int argc, char **argv)
{
int level;
log_remote_level_t log_level = {0};
log_remote_level_t log_level_out = {0};
uint config_type = CM_CONFIG_SET;
char*json_output = NULL;
int level;
log_remote_level_t log_level = {0};
log_remote_level_t log_level_out = {0};
uint config_type = CM_CONFIG_SET;
char*json_output = NULL;
if (argc < 3) {
ULOG_WARNING(g_log, "Not input log level");
return -1;
}
if (argc == 3 && strstr(argv[2], "get") != NULL) {
config_type = CM_CONFIG_GET;
}
else {
config_type = CM_CONFIG_SET;
if ((level = log_str_to_level(argv[2])) < 0) {
ULOG_WARNING(g_log, "Unknown log level:%s", argv[2]);
return -1;
}
log_level.level = (u8)level;
}
if (argc == 3 && strstr(argv[2], "get") != NULL) {
config_type = CM_CONFIG_GET;
}
else {
config_type = CM_CONFIG_SET;
if ((level = log_str_to_level(argv[2])) < 0) {
ULOG_WARNING(g_log, "Unknown log level:%s", argv[2]);
return -1;
}
log_level.level = (u8)level;
}
s2j_json_set_basic_element(json_obj, &log_level, int, level);
int ret = set_log_conf(config_type, json_obj, LOG_CONFIG_REMOTE_LEVEL, &json_output);
@ -166,53 +165,53 @@ int conf_remote_level(cJSON *json_obj, int argc, char **argv)
ULOG_DEBUG(g_log, "Remote level of log whice is configured is success");
}
if (CM_CONFIG_GET == config_type) {
logging_remote_level_json_parse(json_output, &log_level_out);
if (CM_CONFIG_GET == config_type) {
logging_remote_level_json_parse(json_output, &log_level_out);
logging_get_remote_level_print(&log_level_out);
}
return ret;
logging_get_remote_level_print(&log_level_out);
}
return ret;
}
static int logging_remote_json_parse(pointer input, log_remote_host_x_t *config_buff)
{
cJSON *json_obj;
cJSON *json_obj;
if (NULL == config_buff)
{
return -1;
}
if (NULL == config_buff)
{
return -1;
}
json_obj = cJSON_Parse(input);
if(!json_obj)
{
return -1;
}
json_obj = cJSON_Parse(input);
if(!json_obj)
{
return -1;
}
// char *print_str = cJSON_Print(json_obj);
// ULOG_DEBUG(g_log, "remote json parse, json input:%s \n", print_str);
// free(print_str);
// char *print_str = cJSON_Print(json_obj);
// ULOG_DEBUG(g_log, "remote json parse, json input:%s \n", print_str);
// free(print_str);
s2j_create_struct_obj(log_host_x, log_remote_host_x_t);
if(log_host_x == NULL)
{
cJSON_Delete(json_obj);
return -1;
}
s2j_create_struct_obj(log_host_x, log_remote_host_x_t);
if(log_host_x == NULL)
{
cJSON_Delete(json_obj);
return -1;
}
s2j_struct_get_basic_element(log_host_x, json_obj, int, port);
s2j_struct_get_basic_element(log_host_x, json_obj, int, rfc);
S2J_STRUCT_GET_STRING_ELEMENT_N(log_host_x, json_obj, host, LOG_HOST_SZ);
s2j_struct_get_basic_element(log_host_x, json_obj, int, level);
s2j_struct_get_basic_element(log_host_x, json_obj, int, port);
s2j_struct_get_basic_element(log_host_x, json_obj, int, rfc);
S2J_STRUCT_GET_STRING_ELEMENT_N(log_host_x, json_obj, host, LOG_HOST_SZ);
s2j_struct_get_basic_element(log_host_x, json_obj, int, level);
memcpy(config_buff, log_host_x, sizeof(log_remote_host_x_t));
s2j_delete_struct_obj(log_host_x);
cJSON_Delete(json_obj);
memcpy(config_buff, log_host_x, sizeof(log_remote_host_x_t));
return 0;
s2j_delete_struct_obj(log_host_x);
cJSON_Delete(json_obj);
return 0;
}
@ -220,171 +219,171 @@ static int logging_remote_json_parse(pointer input, log_remote_host_x_t *config_
static int logging_remote_json_parse_array(pointer input,
log_remote_host_x_t *config_buff, int *cnt)
{
cJSON *json_obj;
int json_cnt = 0, i = 0;
int used_cnt = 0;
cJSON *json_obj;
int json_cnt = 0, i = 0;
int used_cnt = 0;
json_obj = cJSON_Parse(input);
if(!json_obj)
{
return -1;
}
json_obj = cJSON_Parse(input);
if(!json_obj)
{
return -1;
}
// char *print_str = cJSON_Print(json_obj);
// ULOG_DEBUG(g_log, "remote json parse array, json input:%s \n", print_str);
// free(print_str);
// char *print_str = cJSON_Print(json_obj);
// ULOG_DEBUG(g_log, "remote json parse array, json input:%s \n", print_str);
// free(print_str);
json_cnt = cJSON_GetArraySize(json_obj);
if (json_cnt > MAX_REMOTE_HOST_CNT)
{
used_cnt = MAX_REMOTE_HOST_CNT;
}
else
{
used_cnt = json_cnt;
}
json_cnt = cJSON_GetArraySize(json_obj);
if (json_cnt > MAX_REMOTE_HOST_CNT)
{
used_cnt = MAX_REMOTE_HOST_CNT;
}
else
{
used_cnt = json_cnt;
}
s2j_create_struct_obj(log_host_x, log_remote_host_x_t);
if(log_host_x == NULL)
{
cJSON_Delete(json_obj);
return -1;
}
s2j_create_struct_obj(log_host_x, log_remote_host_x_t);
if(log_host_x == NULL)
{
cJSON_Delete(json_obj);
return -1;
}
*cnt = 0;
for (i = 0; i < used_cnt; i++)
{
cJSON* p_array = cJSON_GetArrayItem(json_obj, i);
if (p_array)
{
memset(log_host_x, 0, sizeof(log_remote_host_x_t));
*cnt = 0;
for (i = 0; i < used_cnt; i++)
{
cJSON* p_array = cJSON_GetArrayItem(json_obj, i);
if (p_array)
{
memset(log_host_x, 0, sizeof(log_remote_host_x_t));
s2j_struct_get_basic_element(log_host_x, p_array, int, port);
s2j_struct_get_basic_element(log_host_x, p_array, int, rfc);
s2j_struct_get_basic_element(log_host_x, p_array, string, host);
s2j_struct_get_basic_element(log_host_x, p_array, int, level);
s2j_struct_get_basic_element(log_host_x, p_array, int, port);
s2j_struct_get_basic_element(log_host_x, p_array, int, rfc);
s2j_struct_get_basic_element(log_host_x, p_array, string, host);
s2j_struct_get_basic_element(log_host_x, p_array, int, level);
memcpy(config_buff+*cnt, log_host_x, sizeof(log_remote_host_x_t));
(*cnt)++;
}
}
memcpy(config_buff+*cnt, log_host_x, sizeof(log_remote_host_x_t));
(*cnt)++;
}
}
s2j_delete_struct_obj(log_host_x);
cJSON_Delete(json_obj);
s2j_delete_struct_obj(log_host_x);
cJSON_Delete(json_obj);
return 0;
return 0;
}
static int logging_remote_level_json_parse(pointer input, log_remote_level_t *config_buff)
{
cJSON *json_obj;
cJSON *json_obj;
if (NULL == config_buff)
{
return -1;
}
if (NULL == config_buff)
{
return -1;
}
json_obj = cJSON_Parse(input);
if (!json_obj)
{
return -1;
}
json_obj = cJSON_Parse(input);
if (!json_obj)
{
return -1;
}
s2j_create_struct_obj(log_remote_level, log_remote_level_t);
if (log_remote_level == NULL)
{
cJSON_Delete(json_obj);
return -1;
}
s2j_create_struct_obj(log_remote_level, log_remote_level_t);
if (log_remote_level == NULL)
{
cJSON_Delete(json_obj);
return -1;
}
s2j_struct_get_basic_element(log_remote_level, json_obj, int, level);
s2j_struct_get_basic_element(log_remote_level, json_obj, int, level);
memcpy(config_buff, log_remote_level, sizeof(log_remote_level_t));
memcpy(config_buff, log_remote_level, sizeof(log_remote_level_t));
s2j_delete_struct_obj(log_remote_level);
cJSON_Delete(json_obj);
s2j_delete_struct_obj(log_remote_level);
cJSON_Delete(json_obj);
return 0;
return 0;
}
static void logging_get_remote_level_print(log_remote_level_t *log_conf)
{
if (NULL == log_conf)
{
return;
}
fprintf(stdout, "--------------------------------------------------------------------------------\n");
fprintf(stdout, " get trap:\n\n");
if (log_conf->level < sizeof(g_level_array) / sizeof(level_str_t))
fprintf(stdout, " level %s\n", g_level_array[log_conf->level].str);
else
fprintf(stdout, " level <invalid_value>\n");
fprintf(stdout, "--------------------------------------------------------------------------------\n");
if (NULL == log_conf)
{
return;
}
ULOG_DEBUG(g_log, "Log level get: level=%u", log_conf->level);
fprintf(stdout, "--------------------------------------------------------------------------------\n");
fprintf(stdout, " get trap:\n\n");
if (log_conf->level < sizeof(g_level_array) / sizeof(level_str_t))
fprintf(stdout, " level %s\n", g_level_array[log_conf->level].str);
else
fprintf(stdout, " level <invalid_value>\n");
fprintf(stdout, "--------------------------------------------------------------------------------\n");
ULOG_DEBUG(g_log, "Log level get: level=%u", log_conf->level);
}
static void logging_get_remote_print(log_remote_host_x_t *log_conf, uint cnt)
{
char *tmp_str=NULL;
if (NULL == log_conf || 0 == cnt)
{
return;
}
if (1 == cnt)
{
fprintf(stdout, "--------------------------------------------------------------------------------\n");
fprintf(stdout, " get host:\n\n");
if (log_conf->level < sizeof(g_level_array) / sizeof(level_str_t))
tmp_str = &g_level_array[log_conf->level].str;
else
tmp_str = "<invalid_value>";
fprintf(stdout, " level %s\n", tmp_str);
fprintf(stdout, " ip_addr %s\n", log_conf->host);
fprintf(stdout, " port %u\n", log_conf->port);
if (log_conf->rfc < sizeof(rfc_tbl) / sizeof(rfc_key_fmt))
tmp_str = &rfc_tbl[log_conf->rfc].fmt;
else
tmp_str = "<invalid_value>";
fprintf(stdout, " RFCfmt %s\n", tmp_str);
fprintf(stdout, "--------------------------------------------------------------------------------\n");
ULOG_DEBUG(g_log, "Log host get: addr=%s, port=%u, log_fmt=%u, level=%u",
log_conf->host, log_conf->port, log_conf->rfc, log_conf->level);
}
else
{
int i=0;
fprintf(stdout, "--------------------------------------------------------------------------------\n");
fprintf(stdout, " get hosts:\n\n");
for (i=0; i<cnt; i++)
{
fprintf(stdout, " host[%d]:\n", i);
if (log_conf[i].level < sizeof(g_level_array) / sizeof(level_str_t))
tmp_str = &g_level_array[log_conf[i].level].str;
else
tmp_str = "<invalid_value>";
fprintf(stdout, " level %s\n", tmp_str);
fprintf(stdout, " ip_addr %s\n", log_conf[i].host);
fprintf(stdout, " port %u\n", log_conf[i].port);
if (log_conf[i].rfc < sizeof(rfc_tbl) / sizeof(rfc_key_fmt))
tmp_str = &rfc_tbl[log_conf[i].rfc].fmt;
else
tmp_str = "<invalid_value>";
fprintf(stdout, " RFCfmt %s\n", tmp_str);
}
fprintf(stdout, "--------------------------------------------------------------------------------\n");
char *tmp_str=NULL;
for (i=0; i<cnt; i++)
{
ULOG_DEBUG(g_log, "Log host get: host[%d]: addr=%s, port=%u, log_fmt=%u, level=%u",
i, log_conf[i].host, log_conf[i].port, log_conf[i].rfc, log_conf[i].level);
}
}
if (NULL == log_conf || 0 == cnt)
{
return;
}
if (1 == cnt)
{
fprintf(stdout, "--------------------------------------------------------------------------------\n");
fprintf(stdout, " get host:\n\n");
if (log_conf->level < sizeof(g_level_array) / sizeof(level_str_t))
tmp_str = &g_level_array[log_conf->level].str;
else
tmp_str = "<invalid_value>";
fprintf(stdout, " level %s\n", tmp_str);
fprintf(stdout, " ip_addr %s\n", log_conf->host);
fprintf(stdout, " port %u\n", log_conf->port);
if (log_conf->rfc < sizeof(rfc_tbl) / sizeof(rfc_key_fmt))
tmp_str = &rfc_tbl[log_conf->rfc].fmt;
else
tmp_str = "<invalid_value>";
fprintf(stdout, " RFCfmt %s\n", tmp_str);
fprintf(stdout, "--------------------------------------------------------------------------------\n");
ULOG_DEBUG(g_log, "Log host get: addr=%s, port=%u, log_fmt=%u, level=%u",
log_conf->host, log_conf->port, log_conf->rfc, log_conf->level);
}
else
{
int i=0;
fprintf(stdout, "--------------------------------------------------------------------------------\n");
fprintf(stdout, " get hosts:\n\n");
for (i=0; i<cnt; i++)
{
fprintf(stdout, " host[%d]:\n", i);
if (log_conf[i].level < sizeof(g_level_array) / sizeof(level_str_t))
tmp_str = &g_level_array[log_conf[i].level].str;
else
tmp_str = "<invalid_value>";
fprintf(stdout, " level %s\n", tmp_str);
fprintf(stdout, " ip_addr %s\n", log_conf[i].host);
fprintf(stdout, " port %u\n", log_conf[i].port);
if (log_conf[i].rfc < sizeof(rfc_tbl) / sizeof(rfc_key_fmt))
tmp_str = &rfc_tbl[log_conf[i].rfc].fmt;
else
tmp_str = "<invalid_value>";
fprintf(stdout, " RFCfmt %s\n", tmp_str);
}
fprintf(stdout, "--------------------------------------------------------------------------------\n");
for (i=0; i<cnt; i++)
{
ULOG_DEBUG(g_log, "Log host get: host[%d]: addr=%s, port=%u, log_fmt=%u, level=%u",
i, log_conf[i].host, log_conf[i].port, log_conf[i].rfc, log_conf[i].level);
}
}
}

View File

@ -20,7 +20,7 @@ int set_log_conf(uint config_type, cJSON *json_obj, uint64 config_id, char **jso
}
ULOG_DEBUG(g_log, "Setting log json is %s", json);
ret_code ret_c = web_config_exec_sync(config_type, config_id,
json, strlen(json),
&output, &output_len);
@ -30,18 +30,18 @@ int set_log_conf(uint config_type, cJSON *json_obj, uint64 config_id, char **jso
ret = 0;
}
if (json_output != NULL)
{
if (CM_CONFIG_GET == config_type || CM_CONFIG_GET_ALL == config_type)
{
ULOG_DEBUG(g_log, "get outputlen:%d, output:%s", output_len, output);
*json_output = output;
}
else
{
*json_output = NULL;
}
}
if (json_output != NULL)
{
if (CM_CONFIG_GET == config_type || CM_CONFIG_GET_ALL == config_type)
{
ULOG_DEBUG(g_log, "get outputlen:%d, output:%s", output_len, output);
*json_output = output;
}
else
{
*json_output = NULL;
}
}
free(json);
return ret;
@ -50,63 +50,63 @@ int set_log_conf(uint config_type, cJSON *json_obj, uint64 config_id, char **jso
int logging_terminal_json_parse(pointer input, pointer config_buff, uint64 conf_id)
{
cJSON *json_obj = NULL;
cJSON *json_obj = NULL;
if (NULL == config_buff) {
return -1;
}
if (NULL == config_buff) {
return -1;
}
json_obj = cJSON_Parse(input);
if (!json_obj)
{
return -1;
}
json_obj = cJSON_Parse(input);
if (!json_obj)
{
return -1;
}
s2j_create_struct_obj(log_terminal, log_console_t);
if (NULL == log_terminal)
{
cJSON_Delete(json_obj);
return -1;
}
s2j_create_struct_obj(log_terminal, log_console_t);
if (NULL == log_terminal)
{
cJSON_Delete(json_obj);
return -1;
}
s2j_struct_get_basic_element(log_terminal, json_obj, int, level);
s2j_struct_get_basic_element(log_terminal, json_obj, int, on);
s2j_struct_get_basic_element(log_terminal, json_obj, string, module);
s2j_struct_get_basic_element(log_terminal, json_obj, int, level);
s2j_struct_get_basic_element(log_terminal, json_obj, int, on);
s2j_struct_get_basic_element(log_terminal, json_obj, string, module);
memcpy(config_buff, log_terminal, sizeof(log_console_t));
memcpy(config_buff, log_terminal, sizeof(log_console_t));
s2j_delete_struct_obj(log_terminal);
cJSON_Delete(json_obj);
s2j_delete_struct_obj(log_terminal);
cJSON_Delete(json_obj);
return 0;
return 0;
}
void logging_get_terminal_console_print(void *log_conf, uint64 config_id)
{
log_console_t *conf = log_conf;
if (NULL == conf)
{
return;
}
fprintf(stdout, "--------------------------------------------------------------------------------\n");
fprintf(stdout, " get %s:\n\n", config_id==LOG_CONFIG_CONSOLE?"console":"terminal");
if (conf->level < sizeof(g_level_array) / sizeof(level_str_t))
fprintf(stdout, " level %s\n", g_level_array[conf->level].str);
else
fprintf(stdout, " level <invalid_value>\n");
fprintf(stdout, " on/off %s\n", conf->on==LOG_ON?"on":"off");
fprintf(stdout, " module %s\n", conf->module);
fprintf(stdout, "--------------------------------------------------------------------------------\n");
log_console_t *conf = log_conf;
if (NULL == conf)
{
return;
}
fprintf(stdout, "--------------------------------------------------------------------------------\n");
fprintf(stdout, " get %s:\n\n", config_id==LOG_CONFIG_CONSOLE?"console":"terminal");
if (conf->level < sizeof(g_level_array) / sizeof(level_str_t))
fprintf(stdout, " level %s\n", g_level_array[conf->level].str);
else
fprintf(stdout, " level <invalid_value>\n");
fprintf(stdout, " on/off %s\n", conf->on==LOG_ON?"on":"off");
fprintf(stdout, " module %s\n", conf->module);
fprintf(stdout, "--------------------------------------------------------------------------------\n");
if (LOG_ON == conf->on) {
ULOG_DEBUG(g_log, "Log %s get: level=%u, module=%s",
(config_id == LOG_CONFIG_CONSOLE)?"console":"monitor",
conf->level,
conf->module);
} else {
ULOG_DEBUG(g_log, "Log %s get: off",
(config_id == LOG_CONFIG_CONSOLE)?"console":"monitor");
}
if (LOG_ON == conf->on) {
ULOG_DEBUG(g_log, "Log %s get: level=%u, module=%s",
(config_id == LOG_CONFIG_CONSOLE)?"console":"monitor",
conf->level,
conf->module);
} else {
ULOG_DEBUG(g_log, "Log %s get: off",
(config_id == LOG_CONFIG_CONSOLE)?"console":"monitor");
}
}

View File

@ -45,21 +45,21 @@ void logging_get_terminal_console_print(void *log_conf, uint64 config_id);
} else { \
ULOG_DEBUG(g_log, "Setting terminal configure of log is success"); \
} \
\
if (CM_CONFIG_GET == config_type) { \
if (logging_terminal_json_parse(json_output, &terminal_out, conf_id) == 0) { \
logging_get_terminal_console_print(&terminal_out, conf_id); \
} \
} \
\
\
if (CM_CONFIG_GET == config_type) { \
if (logging_terminal_json_parse(json_output, &terminal_out, conf_id) == 0) { \
logging_get_terminal_console_print(&terminal_out, conf_id); \
} \
} \
\
return ret; \
}
#define CMD_PARSE_AND_CONFIG_TERMINAL(type, json_obj, argc, argv, conf_id) { \
log_sw_t on = LOG_ON; \
char *str_level = DEFAULT_LOG_LEVEL; \
uint config_type = CM_CONFIG_SET; \
\
uint config_type = CM_CONFIG_SET; \
\
if (argc >= 3) { \
if (strcasecmp(argv[2], "off") == 0) { \
on = LOG_OFF; \

View File

@ -38,68 +38,68 @@ log_cmd_t *get_cb_by_cmd(const char *cmd)
static void logging_usage()
{
int i = 0;
char tmp_str[1024] = "";
fprintf(stdout, "-----------------------------------------------------------------------------------------\n");
fprintf(stdout, "usage of %s:", LOGGING_MODULE_NAME);
for (i = 0; i < (sizeof(g_log_cmd) / sizeof(log_cmd_t)); i++) {
strcat(tmp_str, g_log_cmd[i].cmd);
if (i < (sizeof(g_log_cmd) / sizeof(log_cmd_t))-1) {
strcat(tmp_str, "|");
}
int i = 0;
char tmp_str[1024] = "";
fprintf(stdout, "-----------------------------------------------------------------------------------------\n");
fprintf(stdout, "usage of %s:", LOGGING_MODULE_NAME);
for (i = 0; i < (sizeof(g_log_cmd) / sizeof(log_cmd_t)); i++) {
strcat(tmp_str, g_log_cmd[i].cmd);
if (i < (sizeof(g_log_cmd) / sizeof(log_cmd_t))-1) {
strcat(tmp_str, "|");
}
}
fprintf(stdout, " %s %s\n", LOGGING_MODULE_NAME, tmp_str);
fprintf(stdout, "\n");
fprintf(stdout, " %s %s\n", LOGGING_MODULE_NAME, tmp_str);
fprintf(stdout, "\n");
fprintf(stdout, "1. usage of %s %s:\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " %s %s <level> [<module_name>, defalut is wildcard]]\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " %s %s off\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " %s %s get [<module_name>, defalut is wildcard]]\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " <level> = emerg | alert | crit | err | warn | notice | info | debug\n");
fprintf(stdout, " <module_name> the filtering module_name, only recode this module's log while set\n");
fprintf(stdout, " eg: %s %s info moudle1\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " %s %s off\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " %s %s get module1\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, "\n");
fprintf(stdout, "2. usage of %s %s is simple as %s\n", LOGGING_MODULE_NAME, g_log_cmd[1].cmd, g_log_cmd[0].cmd);
fprintf(stdout, "\n");
fprintf(stdout, "1. usage of %s %s:\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " %s %s <level> [<module_name>, defalut is wildcard]]\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " %s %s off\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " %s %s get [<module_name>, defalut is wildcard]]\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " <level> = emerg | alert | crit | err | warn | notice | info | debug\n");
fprintf(stdout, " <module_name> the filtering module_name, only recode this module's log while set\n");
fprintf(stdout, " eg: %s %s info moudle1\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " %s %s off\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, " %s %s get module1\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
fprintf(stdout, "\n");
fprintf(stdout, "2. usage of %s %s is simple as %s\n", LOGGING_MODULE_NAME, g_log_cmd[1].cmd, g_log_cmd[0].cmd);
fprintf(stdout, "\n");
fprintf(stdout, "3. usage of %s %s:\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s add <ip_addr> [<port>, defalut=514] [<RFCfmt>, defalut=RFC3164fmt]\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s del <ip_addr> [<port>, defalut=514] [<RFCfmt>, defalut=RFC3164fmt]\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s get <ip_addr> [<port>, defalut is wildcard] [<RFCfmt>, defalut is wildcard]\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s getall\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " <ip_addr> is the ip address of remote syslog server\n");
fprintf(stdout, " <port> is the port of remote syslog server\n");
fprintf(stdout, " <RFCfmt> = RFC3164fmt|RFC5424fmt, is the version of syslog format\n");
fprintf(stdout, " eg: %s %s add 192.168.100.1 514 RFC3164fmt\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s del 192.168.100.1 514 RFC3164fmt\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s get 192.168.100.1\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s getall\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, "\n");
fprintf(stdout, "3. usage of %s %s:\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s add <ip_addr> [<port>, defalut=514] [<RFCfmt>, defalut=RFC3164fmt]\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s del <ip_addr> [<port>, defalut=514] [<RFCfmt>, defalut=RFC3164fmt]\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s get <ip_addr> [<port>, defalut is wildcard] [<RFCfmt>, defalut is wildcard]\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s getall\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " <ip_addr> is the ip address of remote syslog server\n");
fprintf(stdout, " <port> is the port of remote syslog server\n");
fprintf(stdout, " <RFCfmt> = RFC3164fmt|RFC5424fmt, is the version of syslog format\n");
fprintf(stdout, " eg: %s %s add 192.168.100.1 514 RFC3164fmt\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s del 192.168.100.1 514 RFC3164fmt\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s get 192.168.100.1\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, " %s %s getall\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
fprintf(stdout, "\n");
fprintf(stdout, "4. usage of %s %s:\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd);
fprintf(stdout, " %s %s <level>\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd);
fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd);
fprintf(stdout, " <level> = emerg | alert | crit | err | warn | notice | info | debug \n");
fprintf(stdout, " eg: %s %s info\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd);
fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd);
fprintf(stdout, "\n");
fprintf(stdout, "4. usage of %s %s:\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd);
fprintf(stdout, " %s %s <level>\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd);
fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd);
fprintf(stdout, " <level> = emerg | alert | crit | err | warn | notice | info | debug \n");
fprintf(stdout, " eg: %s %s info\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd);
fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd);
fprintf(stdout, "\n");
fprintf(stdout, "5. usage of %s %s:\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd);
fprintf(stdout, " %s %s [<level>, default=info] [<file_path>, default=/var/log/syslog-test] [<is_compress>, default=0] [<del_over_days>, default=180] [<del_over_size>, default=0]\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd);
fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd);
fprintf(stdout, " <level> = emerg | alert | crit | err | warn | notice | info | debug\n");
fprintf(stdout, " <file_path> is the path of syslog files saved\n");
fprintf(stdout, " <is_compress> = 0 | 1 , which 0 is syslog files is not compress while 1 is compress\n");
fprintf(stdout, " <del_over_days> is the syslog files life-time (days)\n");
fprintf(stdout, " <del_over_size> is the syslog files life-size (bytes), while 0 is no-check\n");
fprintf(stdout, " eg: %s %s info /var/log/syslog-files 0 100 1024000\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd);
fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd);
fprintf(stdout, "5. usage of %s %s:\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd);
fprintf(stdout, " %s %s [<level>, default=info] [<file_path>, default=/var/log/syslog-test] [<is_compress>, default=0] [<del_over_days>, default=180] [<del_over_size>, default=0]\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd);
fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd);
fprintf(stdout, " <level> = emerg | alert | crit | err | warn | notice | info | debug\n");
fprintf(stdout, " <file_path> is the path of syslog files saved\n");
fprintf(stdout, " <is_compress> = 0 | 1 , which 0 is syslog files is not compress while 1 is compress\n");
fprintf(stdout, " <del_over_days> is the syslog files life-time (days)\n");
fprintf(stdout, " <del_over_size> is the syslog files life-size (bytes), while 0 is no-check\n");
fprintf(stdout, " eg: %s %s info /var/log/syslog-files 0 100 1024000\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd);
fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd);
fprintf(stdout, "-----------------------------------------------------------------------------------------\n");
fprintf(stdout, "-----------------------------------------------------------------------------------------\n");
}
int main(int argc, char **argv)
@ -107,14 +107,14 @@ int main(int argc, char **argv)
int ret = -1;
if (argc < 2) {
fprintf(stdout, "Parameter too few\n");
logging_usage();
logging_usage();
return ret;
}
if (strcmp(argv[1], "-h")==0 || strcmp(argv[1], "--help")==0) {
logging_usage();
return 0;
}
if (strcmp(argv[1], "-h")==0 || strcmp(argv[1], "--help")==0) {
logging_usage();
return 0;
}
g_log = ulog_init(LOGGING_MODULE_NAME, 1);
if (g_log == NULL) {

View File

@ -10,7 +10,7 @@
#include "sev_sched.h"
#define FILTER_CONTENT ":msg,contains,\""MODULE_FMT"\"\n"
#define DEFAULT_CONFIG_FILE_TMP "/etc/log-sched.conf.tmp"
#define DEFAULT_CONFIG_FILE_TMP "/etc/log-sched.conf.tmp"
static int copy_file(const char *src, const char *dst)
@ -18,12 +18,12 @@ static int copy_file(const char *src, const char *dst)
//return -1;
int ret = -1;
FILE *src_fp = NULL,*dst_fp = NULL;
src_fp = fopen(src, "r");
src_fp = fopen(src, "r");
if (src_fp == NULL) {
ULOG_ERR(g_log, "Opening src file:%s is failure:%s", src, strerror(errno));
goto END;
}
dst_fp = fopen(dst, "w");
dst_fp = fopen(dst, "w");
if (dst_fp == NULL) {
ULOG_ERR(g_log, "Opening dst file:%s is failure:%s", src, strerror(errno));
goto END;
@ -32,9 +32,9 @@ static int copy_file(const char *src, const char *dst)
char buff[1024];
int len;
int n;
while((len = fread(buff, 1, sizeof(buff), src_fp)) > 0)
{
n = fwrite(buff, 1, len ,dst_fp);
while((len = fread(buff, 1, sizeof(buff), src_fp)) > 0)
{
n = fwrite(buff, 1, len ,dst_fp);
if (n != len) {
ULOG_ERR(g_log, "Configure file which is written[length:%d, actual len:%n] is failure:%s", n, len, strerror(errno));
goto END;
@ -43,7 +43,7 @@ static int copy_file(const char *src, const char *dst)
if (feof(src_fp) == 0) {
break;
}
}
}
ret = 0;
END:
@ -276,100 +276,100 @@ FAIL:
/* 写配置到配置文件。追加在配置文件最后 */
int write_log_file_conf(const char *p_key_str, const char *p_value_str)
{
char conf_value_str[MAX_LINE_SZ] = "";
char buffer[MAX_LINE_SZ] = "";
char *p_pos = NULL;
int is_exist = 0;
FILE *tmp_conf_fp = NULL;
char conf_value_str[MAX_LINE_SZ] = "";
char buffer[MAX_LINE_SZ] = "";
char *p_pos = NULL;
int is_exist = 0;
FILE *tmp_conf_fp = NULL;
if (NULL == p_key_str || '\0' == p_key_str[0] || NULL == p_value_str) {
ULOG_ERR(g_log, "Bad input");
if (NULL == p_key_str || '\0' == p_key_str[0] || NULL == p_value_str) {
ULOG_ERR(g_log, "Bad input");
return -1;
}
}
/* 定位到起始位置 */
if (fseek(g_conf_fp, 0, SEEK_SET) == -1) {
/* 定位到起始位置 */
if (fseek(g_conf_fp, 0, SEEK_SET) == -1) {
ULOG_ERR(g_log, "Seeknig config to begin is faiure:%s", strerror(errno));
return -1;
}
/* 查看配置是否已存在 */
while (fgets(buffer,MAX_LINE_SZ,g_conf_fp)!=NULL) {
p_pos = strstr(buffer, p_key_str);
if (p_pos != NULL) {
memset(conf_value_str, 0, sizeof(conf_value_str));
strcpy(conf_value_str, p_pos+strlen(p_key_str));
/* 查看配置是否已存在 */
while (fgets(buffer,MAX_LINE_SZ,g_conf_fp)!=NULL) {
p_pos = strstr(buffer, p_key_str);
if (p_pos != NULL) {
memset(conf_value_str, 0, sizeof(conf_value_str));
strcpy(conf_value_str, p_pos+strlen(p_key_str));
is_exist = 1;
break;
}
}
is_exist = 1;
break;
}
}
if (is_exist == 1) {
/* 判断已有配置是否与当前传入配置相同 */
if (strlen(conf_value_str) == strlen(p_value_str) && 0 == strcmp(conf_value_str, p_value_str)) {
/* 无需做任何变更,本函数返回 */
return 0;
}
/* 定位到起始位置 */
if (fseek(g_conf_fp, 0, SEEK_SET) == -1) {
ULOG_ERR(g_log, "Seeknig config to begin is faiure:%s", strerror(errno));
return -1;
}
if (is_exist == 1) {
/* 判断已有配置是否与当前传入配置相同 */
if (strlen(conf_value_str) == strlen(p_value_str) && 0 == strcmp(conf_value_str, p_value_str)) {
/* 无需做任何变更,本函数返回 */
return 0;
}
/* 定位到起始位置 */
if (fseek(g_conf_fp, 0, SEEK_SET) == -1) {
ULOG_ERR(g_log, "Seeknig config to begin is faiure:%s", strerror(errno));
return -1;
}
/* 打开临时文件 */
tmp_conf_fp = fopen(DEFAULT_CONFIG_FILE_TMP, "w+");
if (NULL == tmp_conf_fp){
ULOG_ERR(g_log, "Open temp config file failed: %s", strerror(errno));
return -1;
}
/* 打开临时文件 */
tmp_conf_fp = fopen(DEFAULT_CONFIG_FILE_TMP, "w+");
if (NULL == tmp_conf_fp){
ULOG_ERR(g_log, "Open temp config file failed: %s", strerror(errno));
return -1;
}
/* 将原文件内容写入临时文件,但跳过当前配置相关项 */
while (fgets(buffer,MAX_LINE_SZ,g_conf_fp)!=NULL) {
if (strstr(buffer, p_key_str) != NULL) {
continue;
}
fputs(buffer,tmp_conf_fp);
}
fflush(tmp_conf_fp);
/* 将原文件内容写入临时文件,但跳过当前配置相关项 */
while (fgets(buffer,MAX_LINE_SZ,g_conf_fp)!=NULL) {
if (strstr(buffer, p_key_str) != NULL) {
continue;
}
fputs(buffer,tmp_conf_fp);
}
fflush(tmp_conf_fp);
/* 将临时文件写回原配置文件 */
truncate(g_conf_file, 0);
// fclose(g_conf_fp);
// g_conf_fp = fopen(g_conf_file, "w+");
if (fseek(g_conf_fp, 0, SEEK_SET) == -1) {
ULOG_ERR(g_log, "Seeknig config to begin is faiure:%s", strerror(errno));
return -1;
}
/* 将临时文件写回原配置文件 */
truncate(g_conf_file, 0);
// fclose(g_conf_fp);
// g_conf_fp = fopen(g_conf_file, "w+");
if (fseek(g_conf_fp, 0, SEEK_SET) == -1) {
ULOG_ERR(g_log, "Seeknig config to begin is faiure:%s", strerror(errno));
return -1;
}
if (fseek(tmp_conf_fp, 0, SEEK_SET) == -1) {
ULOG_ERR(g_log, "Seeknig config to begin is faiure:%s", strerror(errno));
return -1;
}
if (fseek(tmp_conf_fp, 0, SEEK_SET) == -1) {
ULOG_ERR(g_log, "Seeknig config to begin is faiure:%s", strerror(errno));
return -1;
}
while (fgets(buffer,MAX_LINE_SZ,tmp_conf_fp)!=NULL) {
fputs(buffer,g_conf_fp);
}
fflush(g_conf_fp);
while (fgets(buffer,MAX_LINE_SZ,tmp_conf_fp)!=NULL) {
fputs(buffer,g_conf_fp);
}
fflush(g_conf_fp);
/* 关闭临时文件 */
fclose(tmp_conf_fp);
tmp_conf_fp = NULL;
}
else {
/* 定位到结束位置 */
if (fseek(g_conf_fp, 0, SEEK_END) == -1) {
ULOG_ERR(g_log, "Seeknig config to end is faiure:%s", strerror(errno));
return -1;
}
}
/* 关闭临时文件 */
fclose(tmp_conf_fp);
tmp_conf_fp = NULL;
}
else {
/* 定位到结束位置 */
if (fseek(g_conf_fp, 0, SEEK_END) == -1) {
ULOG_ERR(g_log, "Seeknig config to end is faiure:%s", strerror(errno));
return -1;
}
}
/* 向配置文件中追加配置项 */
/* 向配置文件中追加配置项 */
char fmt[MAX_LINE_SZ]="";
snprintf(fmt, sizeof(fmt), "%s=%s\n", p_key_str, p_value_str);
snprintf(fmt, sizeof(fmt), "%s=%s\n", p_key_str, p_value_str);
ULOG_DEBUG(g_log, "Configure content is %s", fmt);
int len = strlen(fmt);
int n = fwrite(fmt, 1, len, g_conf_fp);
@ -385,10 +385,10 @@ int write_log_file_conf(const char *p_key_str, const char *p_value_str)
ret_code get_log_file_conf(const char *key_str, char *value_str, int value_len)
{
ret_code ret = RET_OK;
char *pos = NULL;
char *pos2 = NULL;
size_t str_len = 0;
char *pos = NULL;
char *pos2 = NULL;
size_t str_len = 0;
if (fseek(g_conf_fp, 0, SEEK_SET) == -1) {
ULOG_ERR(g_log, "Seeknig config to begin is faiure:%s", strerror(errno));
return ret;
@ -396,56 +396,56 @@ ret_code get_log_file_conf(const char *key_str, char *value_str, int value_len)
ssize_t n;
char *line = NULL;
while ((getline(&line, &n, g_conf_fp)) != -1)
{
if (strstr(line, key_str) == NULL )
{
continue;
}
pos = strstr(line, "=");
if (pos != NULL)
{
if (strlen(pos) <= 1)
{
continue;
}
pos ++;
if ((pos2 = strstr(pos, " ")) != NULL)
{
str_len = strlen(pos) - strlen(pos2);
}
else
{
str_len = strlen(pos);
}
if (str_len >= value_len)
{
ULOG_ERR(g_log, "Get log-sched config %s, but invaild value", key_str);
ret = RET_ERR;
break;
}
memset(value_str, 0, value_len);
strncpy(value_str, pos, str_len);
/* 滤除掉段尾的回车换行 */
if ('\n' == value_str[strlen(value_str)-1])
{
value_str[strlen(value_str)-1] = '\0';
}
while ((getline(&line, &n, g_conf_fp)) != -1)
{
if (strstr(line, key_str) == NULL )
{
continue;
}
pos = strstr(line, "=");
if (pos != NULL)
{
if (strlen(pos) <= 1)
{
continue;
}
pos ++;
if ((pos2 = strstr(pos, " ")) != NULL)
{
str_len = strlen(pos) - strlen(pos2);
}
else
{
str_len = strlen(pos);
}
if (str_len >= value_len)
{
ULOG_ERR(g_log, "Get log-sched config %s, but invaild value", key_str);
ret = RET_ERR;
break;
}
memset(value_str, 0, value_len);
strncpy(value_str, pos, str_len);
/* 滤除掉段尾的回车换行 */
if ('\n' == value_str[strlen(value_str)-1])
{
value_str[strlen(value_str)-1] = '\0';
}
ULOG_DEBUG(g_log, "Get log-sched config %s:%s", key_str, value_str);
break;
}
}
if (NULL!= line)
{
free(line);
}
ULOG_DEBUG(g_log, "Get log-sched config %s:%s", key_str, value_str);
break;
}
}
if (NULL!= line)
{
free(line);
}
return ret;
}

View File

@ -18,14 +18,14 @@
#define SERIAL_PREFIX "ttyS"
#ifndef CM_LOG_CONF_CONSOLE_FILE
#define CM_LOG_CONF_CONSOLE_FILE "/etc/rsyslog.d/log-console.conf"
#define CM_LOG_CONF_CONSOLE_FILE "/etc/rsyslog.d/log-console.conf"
#endif
static int write_console_content(FILE *fp, const u8 level, const char *filter_mod, void *arg)
{
int ret = -1;
FILE *driver_fp = NULL;
driver_fp = fopen(PROC_SERIAL_INFO_PATH, "r");
driver_fp = fopen(PROC_SERIAL_INFO_PATH, "r");
if (driver_fp == NULL) {
ULOG_ERR(g_log, "Opening file:%s is failure:%s", PROC_SERIAL_INFO_PATH, strerror(errno));
return ret;
@ -107,7 +107,7 @@ static int __rpc_conf_log_console(pointer input, const void *arg, char *str_err,
}
void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer data)
void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer data)
{
rpc_conf_proc(conn, input, input_len, sizeof(log_console_t), __rpc_conf_log_console, NULL);
@ -134,71 +134,71 @@ void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer
ret_code console_initial()
{
ret_code ret = RET_ERR;
FILE *fp = NULL;
char *pos = NULL;
char *pos2 = NULL;
char ttyfile_str[128] = "";
fp = fopen(CM_LOG_CONF_CONSOLE_FILE, "r");
if (NULL == fp) {
return ret;
}
FILE *fp = NULL;
char *pos = NULL;
char *pos2 = NULL;
char ttyfile_str[128] = "";
fp = fopen(CM_LOG_CONF_CONSOLE_FILE, "r");
if (NULL == fp) {
return ret;
}
if (fseek(fp, 0, SEEK_SET) == -1)
{
{
ULOG_ERR(g_log, "Seeknig config to begin is faiure:%s", strerror(errno));
fclose(fp);
fclose(fp);
return ret;
}
ssize_t n;
ssize_t n;
char *line = NULL;
int str_len;
while ((getline(&line, &n, fp)) != -1)
{
pos = strstr(line, "/");
if (pos != NULL)
{
if ((pos2 = strstr(pos, " ")) != NULL)
{
str_len = strlen(pos) - strlen(pos2);
}
else
{
str_len = strlen(pos);
}
memset(ttyfile_str, 0, sizeof(ttyfile_str));
strncpy(ttyfile_str, pos, str_len);
/* 滤除掉段尾的回车换行 */
if ('\n' == ttyfile_str[strlen(ttyfile_str)-1])
{
ttyfile_str[strlen(ttyfile_str)-1] = '\0';
}
{
pos = strstr(line, "/");
if (pos != NULL)
{
if ((pos2 = strstr(pos, " ")) != NULL)
{
str_len = strlen(pos) - strlen(pos2);
}
else
{
str_len = strlen(pos);
}
memset(ttyfile_str, 0, sizeof(ttyfile_str));
strncpy(ttyfile_str, pos, str_len);
/* 滤除掉段尾的回车换行 */
if ('\n' == ttyfile_str[strlen(ttyfile_str)-1])
{
ttyfile_str[strlen(ttyfile_str)-1] = '\0';
}
if(modify_authorizing(ttyfile_str) == RET_OK)
{
ULOG_DEBUG(g_log, "Modify authorizing %s successed.", ttyfile_str);
}
else
{
ULOG_DEBUG(g_log, "Modify authorizing %s failed.", ttyfile_str);
}
}
if(modify_authorizing(ttyfile_str) == RET_OK)
{
ULOG_DEBUG(g_log, "Modify authorizing %s successed.", ttyfile_str);
}
else
{
ULOG_DEBUG(g_log, "Modify authorizing %s failed.", ttyfile_str);
}
}
}
if (NULL != line)
{
free(line);
}
if (NULL != line)
{
free(line);
}
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
ret = RET_OK;
if (NULL != fp)
{
fclose(fp);
}
return ret;
}

View File

@ -16,7 +16,7 @@
#define STR_COMPRESS " compress\n"
#define LOG_CONF_KEY_FILE_MAX_SIZE_STR "file.max_size"
#define LOG_CONF_KEY_FILE_MAX_SIZE_STR "file.max_size"
/*
typedef struct _level_str {
@ -85,7 +85,7 @@ static int conf_log_file(const log_file_t *conf)
{
int ret = -1;
u32 max_level = MAX_LOG_LEVEL_VALUE;
char value_str[128] = "";
char value_str[128] = "";
if (conf->level > max_level) {
ULOG_WARNING(g_log, "Configure log level:%u more than max value:%u", conf->level, max_level);
return -1;
@ -111,15 +111,15 @@ static int conf_log_file(const log_file_t *conf)
return -1;
}
/* 将日志文件大小上限写入本程序配置文件中 */
memset(value_str, 0, sizeof(value_str));
/* 将日志文件大小上限写入本程序配置文件中 */
memset(value_str, 0, sizeof(value_str));
if (strlen(conf->del_over_size) > 0) {
sprintf(value_str, "%s", conf->del_over_size);
sprintf(value_str, "%s", conf->del_over_size);
}
if (write_log_file_conf(LOG_CONF_KEY_FILE_MAX_SIZE_STR, value_str) != 0) {
ULOG_ERR(g_log, "Del-over-size which is written is failure");
return -1;
}
if (write_log_file_conf(LOG_CONF_KEY_FILE_MAX_SIZE_STR, value_str) != 0) {
ULOG_ERR(g_log, "Del-over-size which is written is failure");
return -1;
}
ret = 0;
return ret;
@ -134,7 +134,7 @@ static int __rpc_conf_log_file(pointer input, const void *arg, char *str_err, in
return 0;
}
void rpc_conf_log_file(rpc_conn *conn, pointer input, int input_len, pointer data)
void rpc_conf_log_file(rpc_conn *conn, pointer input, int input_len, pointer data)
{
rpc_conf_proc(conn, input, input_len, sizeof(log_file_t), __rpc_conf_log_file, NULL);
}

View File

@ -17,8 +17,8 @@
#define MAX_EVENT_NUMBER 64
#define LOG_DEV_PTY_DIR LOG_DEV_DIR"pts/"
#define LOG_CONF_PTY_FILE_NAME "log-pty.conf"
#define LOG_CONF_KEY_PTY_LEVEL_STR "pty.level"
#define LOG_CONF_KEY_PTY_MODULE_STR "pty.module"
#define LOG_CONF_KEY_PTY_LEVEL_STR "pty.level"
#define LOG_CONF_KEY_PTY_MODULE_STR "pty.module"
pthread_mutex_t g_mutex_pty;
@ -32,41 +32,41 @@ static int write_pty_content(FILE *fp, const u8 level, const char *filter_mod, v
static ret_code write_pty_conf()
{
char value_str[128]="";
uint level = LOG_INFO;
char *module = NULL;
ret_code ret = RET_OK;
uint level = LOG_INFO;
char *module = NULL;
ret_code ret = RET_OK;
memset(value_str, 0, sizeof(value_str));
sprintf(value_str, "%s%s", LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME);
if (access(value_str, 0) == 0)
{
/* 获取配置 */
memset(value_str, 0, sizeof(value_str));
if (get_log_file_conf(LOG_CONF_KEY_PTY_LEVEL_STR, value_str, sizeof(value_str)) == 0)
{
level = atoi(value_str);
}
memset(value_str, 0, sizeof(value_str));
sprintf(value_str, "%s%s", LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME);
if (access(value_str, 0) == 0)
{
/* 获取配置 */
memset(value_str, 0, sizeof(value_str));
if (get_log_file_conf(LOG_CONF_KEY_PTY_LEVEL_STR, value_str, sizeof(value_str)) == 0)
{
level = atoi(value_str);
}
memset(value_str, 0, sizeof(value_str));
if (get_log_file_conf(LOG_CONF_KEY_PTY_MODULE_STR, value_str, sizeof(value_str)) == 0)
{
module = value_str;
}
memset(value_str, 0, sizeof(value_str));
if (get_log_file_conf(LOG_CONF_KEY_PTY_MODULE_STR, value_str, sizeof(value_str)) == 0)
{
module = value_str;
}
pthread_mutex_lock(&g_mutex_pty);
int ret_conf = log_conf((u8)level, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, module,
write_pty_content, NULL);
write_pty_content, NULL);
pthread_mutex_unlock(&g_mutex_pty);
if (ret_conf != 0)
{
ULOG_ERR(g_log, "Log's pty configure which is written is failure");
ret = RET_ERR;
}
else
{
ULOG_DEBUG(g_log, "Pty config level(%u) and module(%s) successed.", level, module!=NULL?module:"NULL");
}
}
if (ret_conf != 0)
{
ULOG_ERR(g_log, "Log's pty configure which is written is failure");
ret = RET_ERR;
}
else
{
ULOG_DEBUG(g_log, "Pty config level(%u) and module(%s) successed.", level, module!=NULL?module:"NULL");
}
}
return ret;
}
@ -237,18 +237,18 @@ static int write_pty_content(FILE *fp, const u8 level, const char *filter_mod, v
ULOG_DEBUG(g_log, "pty name:%s", ptr->d_name);
if (snprintf(path, sizeof(path), "%s%s", LOG_DEV_PTY_DIR, ptr->d_name) < 0) {
ULOG_ERR(g_log, "Setting pty of log[%s] is failure", ptr->d_name);
closedir(dir);
closedir(dir);
return -1;
}
if (write_conf_content_authorizing(fp, level, filter_mod, path) != 0) {
ULOG_ERR(g_log, "Writing pty[module:%s] of log is failure", filter_mod);
closedir(dir);
closedir(dir);
return -1;
}
}
closedir(dir);
closedir(dir);
if (start_dev_pty_monitor() != RET_OK) {
ULOG_ERR(g_log, "Starting pty monitor is failure");
@ -261,7 +261,7 @@ static int write_pty_content(FILE *fp, const u8 level, const char *filter_mod, v
static int config_log_pty(const log_pty_t *conf)
{
int ret = -1;
char value_str[128]="";
char value_str[128]="";
switch (conf->on)
{
@ -269,17 +269,17 @@ static int config_log_pty(const log_pty_t *conf)
stop_dev_pty_monitor();
ret = log_off_with_file(LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME);
/* off时将log-sched配置文件中pty日志级别调成默认值info即level=6 */
if (0 == ret) {
memset(value_str, 0, sizeof(value_str));
snprintf(value_str, sizeof(value_str), "%u", LOG_INFO);
if (write_log_file_conf(LOG_CONF_KEY_PTY_LEVEL_STR, value_str) != 0) {
ULOG_ERR(g_log, "Pty-level which is written is failure");
return -1;
}
}
/* off时将log-sched配置文件中pty日志级别调成默认值info即level=6 */
if (0 == ret) {
memset(value_str, 0, sizeof(value_str));
snprintf(value_str, sizeof(value_str), "%u", LOG_INFO);
if (write_log_file_conf(LOG_CONF_KEY_PTY_LEVEL_STR, value_str) != 0) {
ULOG_ERR(g_log, "Pty-level which is written is failure");
return -1;
}
}
break;
case LOG_ON:
pthread_mutex_lock(&g_mutex_pty);
ret = log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, conf->module,
@ -291,23 +291,23 @@ static int config_log_pty(const log_pty_t *conf)
ret = 0;
}
/* 写pty日志级别与模块名称到log-sched配置文件 */
if (0 == ret) {
memset(value_str, 0, sizeof(value_str));
sprintf(value_str, "%u", conf->level);
if (write_log_file_conf(LOG_CONF_KEY_PTY_LEVEL_STR, value_str) != 0) {
ULOG_ERR(g_log, "Pty-level which is written is failure");
return -1;
}
/* 写pty日志级别与模块名称到log-sched配置文件 */
if (0 == ret) {
memset(value_str, 0, sizeof(value_str));
sprintf(value_str, "%u", conf->level);
if (write_log_file_conf(LOG_CONF_KEY_PTY_LEVEL_STR, value_str) != 0) {
ULOG_ERR(g_log, "Pty-level which is written is failure");
return -1;
}
memset(value_str, 0, sizeof(value_str));
sprintf(value_str, "%s", conf->module);
if (write_log_file_conf(LOG_CONF_KEY_PTY_MODULE_STR, value_str) != 0) {
ULOG_ERR(g_log, "Pty-module which is written is failure");
return -1;
}
}
memset(value_str, 0, sizeof(value_str));
sprintf(value_str, "%s", conf->module);
if (write_log_file_conf(LOG_CONF_KEY_PTY_MODULE_STR, value_str) != 0) {
ULOG_ERR(g_log, "Pty-module which is written is failure");
return -1;
}
}
break;
default:
ULOG_WARNING(g_log, "Unknown on value:%u", conf->on);
@ -326,7 +326,7 @@ static int __rpc_conf_log_pty(pointer input, const void *arg, char *str_err, int
return 0;
}
void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data)
void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data)
{
rpc_conf_proc(conn, input, input_len, sizeof(log_pty_t), __rpc_conf_log_pty, NULL);
}
@ -338,14 +338,14 @@ ret_code pty_initial()
ULOG_DEBUG(g_log, "Initiating pthread lock is failure(cdoe:%d)", thread_ret);
}
ret_code ret = write_pty_conf();
ret_code ret = write_pty_conf();
if (ret != RET_OK) {
ULOG_DEBUG(g_log, "Initiating pty is failure(cdoe:%d)", ret);
} else {
ULOG_INFO(g_log, "Initiating pty is success");
}
return ret;
return ret;
}
ret_code pty_exit()
@ -356,7 +356,7 @@ ret_code pty_exit()
ret = RET_ERR;
ULOG_DEBUG(g_log, "Destroying pthread lock is failure(cdoe:%d)", thread_ret);
}
stop_dev_pty_monitor();
return ret;
stop_dev_pty_monitor();
return ret;
}

View File

@ -69,7 +69,7 @@ static int remote_conf_content(FILE *fp, const u8 level, const char *filter_mod,
char path[MAX_PATH_SZ];
char *line = NULL;
snprintf(path, sizeof(path), BAK_FILE, LOG_CONF_REMOTE_FILE_NAME);
bak_fp = fopen(path, "r");
bak_fp = fopen(path, "r");
if (bak_fp == NULL) {
if (errno == ENOENT) {
goto FINAL_PHASE;
@ -128,7 +128,7 @@ static int remote_conf_level_content(FILE *fp, const u8 level)
ULOG_DEBUG(g_log, "[remote-level]:Buildbackup path(%s) is failure", BAK_FILE, LOG_CONF_REMOTE_FILE_NAME);
return -1;
}
bak_fp = fopen(path, "r");
bak_fp = fopen(path, "r");
if (bak_fp == NULL) {
ULOG_ERR(g_log, "Opening remote backup file:%s is failure:%s", path, strerror(errno));
return -1;
@ -312,7 +312,7 @@ static int config_log_remote_level(const log_remote_level_t *level)
return 0;
}
static void rpc_conf_log_remote(const log_op_t op, rpc_conn *conn, pointer input, int input_len, pointer data)
static void rpc_conf_log_remote(const log_op_t op, rpc_conn *conn, pointer input, int input_len, pointer data)
{
char str_err[1024];
@ -353,7 +353,7 @@ static int __rpc_conf_log_remote(pointer input, const void *arg, char *str_err,
return ret;
}
void rpc_conf_log_add_remote(rpc_conn *conn, pointer input, int input_len, pointer data)
void rpc_conf_log_add_remote(rpc_conn *conn, pointer input, int input_len, pointer data)
{
//rpc_conf_log_remote(LOG_REMOTE_OP_ADD, conn, input, input_len, data);
@ -361,7 +361,7 @@ void rpc_conf_log_add_remote(rpc_conn *conn, pointer input, int input_len, point
rpc_conf_proc(conn, input, input_len, sizeof(log_remote_host_t), __rpc_conf_log_remote, (void *)&op);
}
void rpc_conf_log_del_remote(rpc_conn *conn, pointer input, int input_len, pointer data)
void rpc_conf_log_del_remote(rpc_conn *conn, pointer input, int input_len, pointer data)
{
//rpc_conf_log_remote(LOG_REMOTE_OP_DEL, conn, input, input_len, data);
@ -378,7 +378,7 @@ static int __rpc_conf_log_remote_level(pointer input, const void *arg, char *str
return ret;
}
void rpc_conf_log_remote_level(rpc_conn *conn, pointer input, int input_len, pointer data)
void rpc_conf_log_remote_level(rpc_conn *conn, pointer input, int input_len, pointer data)
{
rpc_conf_proc(conn, input, input_len, sizeof(log_remote_level_t), __rpc_conf_log_remote_level, NULL);
}

View File

@ -28,12 +28,12 @@ typedef ret_code (*exit_cb)();
typedef struct _log_opt {
char type[20];
initial_cb init_func;
exit_cb exit_func;
exit_cb exit_func;
} log_opt_t;
log_opt_t g_log_opt[] = {
{"console", console_initial, NULL},
{"monitor", pty_initial, pty_exit}
{"console", console_initial, NULL},
{"monitor", pty_initial, pty_exit}
};
@ -79,22 +79,22 @@ int main(int argc, char **argv)
}
}
/* 各类配置初始化 */
for (int i = 0; i < (sizeof(g_log_opt) / sizeof(log_opt_t)); i++) {
if ( NULL != g_log_opt[i].init_func) {
g_log_opt[i].init_func();
}
/* 各类配置初始化 */
for (int i = 0; i < (sizeof(g_log_opt) / sizeof(log_opt_t)); i++) {
if ( NULL != g_log_opt[i].init_func) {
g_log_opt[i].init_func();
}
}
/* 重启syslog */
sev_restart();
/* 重启syslog */
sev_restart();
rpc_server *server = rpc_server_create_ex(RPC_MODULE_SYSLOG_NAME);
if (server == NULL)
if (server == NULL)
{
ULOG_ERR(g_log, "start server error");
goto END;
}
goto END;
}
if (log_sev_init() != 0) {
ULOG_INFO(g_log, "Log service which is initited is failure");
@ -106,7 +106,7 @@ int main(int argc, char **argv)
ULOG_INFO(g_log, "Server of log schedule is started");
/* 注册配置处理函数 */
rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, CONF_LOG_FILE_FUNC, rpc_conf_log_file);
rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, CONF_LOG_FILE_FUNC, rpc_conf_log_file);
rpc_server_regservice(server, SERIVCE_LOG_CONSOLE_NAME, CONF_LOG_CONSOLE_FUNC, rpc_conf_log_console);
rpc_server_regservice(server, SERVICE_LOG_PTY_NAME, CONF_LOG_PTY_FUNC, rpc_conf_log_pty);
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_ADD_HOST_FUNC, rpc_conf_log_add_remote);
@ -124,14 +124,14 @@ int main(int argc, char **argv)
strcpy(console.module_name, "111");
console.level = LOG_DEBUG;
console.on = 1;
rpc_conf_log_console(NULL, &console, sizeof(console), NULL);
rpc_conf_log_console(NULL, &console, sizeof(console), NULL);
log_pty_t tty = {0};
//strcpy(tty.module_name, "111");
tty.level = LOG_DEBUG;
tty.on = 1;
rpc_conf_log_pty(NULL, &tty, sizeof(tty), NULL);
rpc_conf_log_pty(NULL, &tty, sizeof(tty), NULL);
log_remote_host_t remote = {0};
strcpy(remote.host, "192.168.3.11");
@ -149,13 +149,13 @@ int main(int argc, char **argv)
ULOG_INFO(g_log, "%s is shutdown", LOG_SCHED_MODULE_NAME);
END:
/* 各类配置退出前的收尾 */
for (int i = 0; i < (sizeof(g_log_opt) / sizeof(log_opt_t)); i++) {
if ( NULL != g_log_opt[i].exit_func) {
g_log_opt[i].exit_func();
}
/* 各类配置退出前的收尾 */
for (int i = 0; i < (sizeof(g_log_opt) / sizeof(log_opt_t)); i++) {
if ( NULL != g_log_opt[i].exit_func) {
g_log_opt[i].exit_func();
}
}
if (g_conf_fp != NULL) {
fclose(g_conf_fp);
}

View File

@ -21,7 +21,7 @@ static volatile sev_state_t g_sev_state = SEV_STATE_WAIT;
void sev_restart()
{
ULOG_DEBUG(g_log, "Log service is restarting");
ULOG_DEBUG(g_log, "Log service is restarting");
FILE *pp = popen(SEV_CMD, "r");
if (pp == NULL) {
@ -31,17 +31,17 @@ void sev_restart()
char buff[256];
while(fread(buff, 1, sizeof(buff), pp) > 0)
{
ULOG_ERR(g_log, "Executing cmd:%s is failure, response content is %s", SEV_CMD, buff);
{
ULOG_ERR(g_log, "Executing cmd:%s is failure, response content is %s", SEV_CMD, buff);
goto END;
}
}
ULOG_INFO(g_log, "Restarting log service is success");
END:
if (pp != NULL) {
pclose(pp);
}
//event_del(signal);
//event_del(signal);
}
void sev_loop()

View File

@ -15,13 +15,13 @@ ulog_t *ulog_init(const char *module_name, u8 is_print)
ulog_t *log;
u32 len = 0;
if (NULL == module_name) {
fprintf(stderr, "Bad input: module_name is NULL\n");
if (NULL == module_name) {
fprintf(stderr, "Bad input: module_name is NULL\n");
return NULL;
}
len = strlen(module_name);
}
len = strlen(module_name);
if (len > MAX_MODULE_NAME_SZ) {
fprintf(stderr, "The length:%d of module_name can't more than %d\n", len, MAX_MODULE_NAME_SZ);
return NULL;
@ -33,7 +33,7 @@ ulog_t *ulog_init(const char *module_name, u8 is_print)
return NULL;
}
strncpy(log->module_name, module_name, len);
log->module_name[len] = '\0';
log->module_name[len] = '\0';
int opt = LOG_PERROR |LOG_PID;
if (is_print > 0) {

View File

@ -12,89 +12,89 @@ ulog_t *g_log = NULL;
static void test_ulog_api()
{
ULOG_DEBUG (g_log, "test for ulog_api %s", "debug");
ULOG_INFO (g_log, "test for ulog_api %s", "info");
ULOG_NOTICE (g_log, "test for ulog_api %s", "notice");
ULOG_WARNING(g_log, "test for ulog_api %s", "warning");
ULOG_ERR (g_log, "test for ulog_api %s", "err");
ULOG_CRIT (g_log, "test for ulog_api %s", "crit");
ULOG_ALERT (g_log, "test for ulog_api %s", "alert");
ULOG_EMERG (g_log, "test for ulog_api %s", "emerg");
ULOG_DEBUG (g_log, "test for ulog_api %s", "debug");
ULOG_INFO (g_log, "test for ulog_api %s", "info");
ULOG_NOTICE (g_log, "test for ulog_api %s", "notice");
ULOG_WARNING(g_log, "test for ulog_api %s", "warning");
ULOG_ERR (g_log, "test for ulog_api %s", "err");
ULOG_CRIT (g_log, "test for ulog_api %s", "crit");
ULOG_ALERT (g_log, "test for ulog_api %s", "alert");
ULOG_EMERG (g_log, "test for ulog_api %s", "emerg");
}
static void ulog_test_usage(const char *pname)
{
if (NULL == pname)
{
return;
}
fprintf(stderr, "--------------------------------------------------------\n");
fprintf(stderr, " usage of %s:\n", pname);
fprintf(stderr, " %s [-d] [-a module_name] [-h]\n", pname);
fprintf(stderr, " \n");
fprintf(stderr, " -d: daemon\n");
fprintf(stderr, " -a: set module name, no longer than 16 bytes\n");
fprintf(stderr, " -h: help\n");
fprintf(stderr, "--------------------------------------------------------\n");
if (NULL == pname)
{
return;
}
fprintf(stderr, "--------------------------------------------------------\n");
fprintf(stderr, " usage of %s:\n", pname);
fprintf(stderr, " %s [-d] [-a module_name] [-h]\n", pname);
fprintf(stderr, " \n");
fprintf(stderr, " -d: daemon\n");
fprintf(stderr, " -a: set module name, no longer than 16 bytes\n");
fprintf(stderr, " -h: help\n");
fprintf(stderr, "--------------------------------------------------------\n");
}
/* usage:
test_ulog_api
test_ulog_api -a test_ulog_api
test_ulog_api -a test2
test_ulog_api -a 123456789012345
test_ulog_api -a 1234567890123456
test_ulog_api -a 12345678901234567
test_ulog_api
test_ulog_api -a test_ulog_api
test_ulog_api -a test2
test_ulog_api -a 123456789012345
test_ulog_api -a 1234567890123456
test_ulog_api -a 12345678901234567
test_ulog_api -d
test_ulog_api -d -a test_ulog_api
test_ulog_api -d -a test2
test_ulog_api -d -a 123456789012345
test_ulog_api -d -a 1234567890123456
test_ulog_api -d -a 12345678901234567
test_ulog_api -d
test_ulog_api -d -a test_ulog_api
test_ulog_api -d -a test2
test_ulog_api -d -a 123456789012345
test_ulog_api -d -a 1234567890123456
test_ulog_api -d -a 12345678901234567
*/
int main(int argc, char **argv)
{
char *options = "da:h";
int opt;
u8 run_daemon = 0;
char module_name[MAX_MODULE_NAME_SZ+4] = "";
u8 run_daemon = 0;
char module_name[MAX_MODULE_NAME_SZ+4] = "";
while ((opt = getopt(argc, argv, options)) != -1) {
while ((opt = getopt(argc, argv, options)) != -1) {
switch (opt) {
case 'd':
run_daemon = 1;
break;
case 'a':
memset(module_name, 0, MAX_MODULE_NAME_SZ+4);
strncpy(module_name, optarg, MAX_MODULE_NAME_SZ+3);
break;
case 'h':
ulog_test_usage(argv[0]);
return 0;
case 'a':
memset(module_name, 0, MAX_MODULE_NAME_SZ+4);
strncpy(module_name, optarg, MAX_MODULE_NAME_SZ+3);
break;
case 'h':
ulog_test_usage(argv[0]);
return 0;
}
}
g_log = ulog_init(module_name, run_daemon);
if (NULL == g_log)
{
goto END;
}
g_log = ulog_init(module_name, run_daemon);
if (NULL == g_log)
{
goto END;
}
if (run_daemon) {
if (run_daemon) {
if (daemon(0, 0) == -1) {
ULOG_ERR(g_log, "Setting daemon running is failure:%s", strerror(errno));
goto END;
}
}
test_ulog_api();
test_ulog_api();
END:
if (NULL != g_log)
{
ulog_close(g_log);
}
if (NULL != g_log)
{
ulog_close(g_log);
}
return 0;
}