#include #include #include #include #include "ulog_api.h" #include "ulog_in.h" 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"); } 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"); } /* 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 -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] = ""; 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; } } g_log = ulog_init(module_name, run_daemon); if (NULL == g_log) { goto END; } 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(); END: if (NULL != g_log) { ulog_close(g_log); } return 0; }