81 lines
1.9 KiB
C
Executable File
81 lines
1.9 KiB
C
Executable File
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
|
|
#include "rpc_server.h"
|
|
#include "ulog_api.h"
|
|
#include "log_file.h"
|
|
#include "log_console.h"
|
|
#include "log_tty.h"
|
|
#include "rpc_module.h"
|
|
|
|
|
|
#define LOG_SCHED_MODULE_NAME "log-sched"
|
|
#define SERVICE_LOG_FILE_NAME "log-file"
|
|
|
|
ulog_t *g_log = NULL;
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int run_daemon = 0;
|
|
char *options = "d";
|
|
int opt;
|
|
|
|
while ((opt = getopt(argc, argv, options)) != -1) {
|
|
switch (opt) {
|
|
case 'd':
|
|
run_daemon = 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
g_log = ulog_init(LOG_SCHED_MODULE_NAME, !run_daemon);
|
|
if (g_log == NULL) {
|
|
fprintf(stderr, "Initiating ulog is failure");
|
|
return 1;
|
|
}
|
|
|
|
if (run_daemon) {
|
|
if (daemon(0, 0) == -1) {
|
|
ULOG_ERR(g_log, "Setting daemon running is failure:%s", strerror(errno));
|
|
goto END;
|
|
}
|
|
}
|
|
|
|
rpc_server *server = rpc_server_create_ex(RPC_MODULE_SYSLOG_NAME);
|
|
if (server == NULL)
|
|
{
|
|
ULOG_ERR(g_log, "start server error");
|
|
return 1;
|
|
|
|
}
|
|
ULOG_INFO(g_log, "Server of log schedule is started");
|
|
|
|
/* 注册配置处理函数 */
|
|
rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, "conf_log_file", rpc_conf_log_file);
|
|
|
|
log_file_t log = {0};
|
|
log.is_compress = LOG_UNCOMPRESS; //LOG_COMPRESS;
|
|
log.del_over_days = 10;
|
|
log.level = LOG_DEBUG;
|
|
rpc_conf_log_file(NULL, &log, sizeof(log), NULL);
|
|
|
|
log_console_t console = {0};
|
|
strcpy(console.module_name, "111");
|
|
console.level = LOG_DEBUG;
|
|
console.on = 1;
|
|
rpc_conf_log_console(NULL, &console, sizeof(console), NULL);
|
|
|
|
|
|
log_tty_t tty = {0};
|
|
strcpy(tty.module_name, "111");
|
|
tty.level = LOG_DEBUG;
|
|
tty.on = 1;
|
|
rpc_conf_log_tty(NULL, &tty, sizeof(tty), NULL);
|
|
END:
|
|
ulog_close(g_log);
|
|
return 0;
|
|
}
|