int main(int argc, char **argv) { char position1[255]; char position2[255]; zt_log_ty * logger; zt_log_ty * lsyslog; /* set the progname before calling syslog */ zt_progname(argv[0], STRIP_DIR); lsyslog = zt_log_syslog(); logger = zt_log_logger(lsyslog); zt_log_set_level(lsyslog, zt_log_debug); zt_log_printf( zt_log_emerg, "*emergency* message" ); zt_log_printf( zt_log_alert, "*alert* message" ); zt_log_printf( zt_log_crit, "*critical* message" ); zt_log_printf( zt_log_err, "*error* message" ); zt_log_printf( zt_log_warning, "*warning* message" ); zt_log_printf( zt_log_notice, "*notice* message" ); zt_log_printf( zt_log_info, "*info* message" ); zt_log_printf( zt_log_debug, "*debug* message" ); zt_log_set_opts(lsyslog, (ZT_LOG_RAW)); /* these need to be on the same line for the test to work */ sprintf(position1, "(%s:%d)", __FILE__, __LINE__); ZT_LOG_XDEBUG( "LOG_DEBUG" ); sprintf(position2, "(%s:%d)", __FILE__, __LINE__); ZT_LOG_DEBUG_INFO(), zt_log_lprintf(lsyslog, zt_log_debug, "lprintf with debugging"); zt_log_close(lsyslog); zt_log_logger(logger); return 0; } /* basic_tests */
zt_log_ty * zt_log_syslog2(int opt, int facility) { #if HAVE_SYSLOG char * name = zt_progname(0, 0); int sysopts = 0; if (opt & ZT_LOG_WITH_PID) { sysopts |= LOG_PID; } openlog(name ? name : "Set name with progname call", sysopts, facility); return zt_log_new(&vtbl, 0); #else /* if HAVE_SYSLOG */ zt_log_ty * logger = zt_log_stderr(ZT_LOG_EMU_SYSLOG); zt_log_printf(zt_log_crit, "Syslog not supported on this platform: falling back to zt_log_stderr"); return logger; #endif /* HAVE_SYSLOG */ }
#include <zt_progname.h> #include <zt_cstr.h> #include <zt_unit.h> static char * argv[] = { "test_app", NULL }; static void basic_tests(struct zt_unit_test *test, void *data UNUSED) { char * name = NULL; char * path = NULL; char * npath = NULL; /* char nname[PATH_MAX+1]; */ char cwd[PATH_MAX+1]; name = zt_progname(argv[0], 0); ZT_UNIT_ASSERT(test, (!strcmp(name, argv[0]))); name = zt_progname(NULL, 0); ZT_UNIT_ASSERT(test, (!strcmp(name, argv[0]))); name = zt_progname("foo", 0); ZT_UNIT_ASSERT(test, (!strcmp(name, "foo"))); /* test the progpath */ if(getcwd(cwd, PATH_MAX) == NULL) { ZT_UNIT_ASSERT(test, 0==1); } path = zt_progpath(NULL); ZT_UNIT_ASSERT(test, (!strcmp(path, "*UNKNOWN*")));