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 */
void zt_log_lstrerror(zt_log_ty *log, zt_log_level level, int errnum, char *fmt, ...) { va_list ap; size_t llen; char * nfmt; if (!log) { log = zt_log_logger(NULL); } if (level > log->level) { return; } llen = strlen(fmt); nfmt = (char *)malloc(llen + 256); memcpy(nfmt, fmt, llen); nfmt[llen] = ':'; nfmt[llen + 1] = ' '; strerror_r(errnum, nfmt + (llen + 2), 255 - 2); va_start(ap, fmt); zt_log_lvprintf(log, level, nfmt, ap); va_end(ap); free(nfmt); }
zt_log_level zt_log_get_level(zt_log_ty *log) { if (!log) { log = zt_log_logger(NULL); } return log->level; }
unsigned int zt_log_get_opts(zt_log_ty *log) { if (!log) { log = zt_log_logger(NULL); } return log->opts; }
static void log_atexit(void * data) { zt_log_ty * logp = data; logp = zt_log_logger(NULL); if(logp) { zt_log_close(logp); } }
void zt_log_close(zt_log_ty *log) { if (!log) { log = zt_log_logger(NULL); } if (log->vtbl->destructor) { log->vtbl->destructor(log); } }
void zt_log_get_debug_info(zt_log_ty *log, char **file, int *line, char **func) { if (!log) { log = zt_log_logger(NULL); } *file = log->file; *line = log->line; *func = log->function; }
void zt_log_set_debug_info(zt_log_ty *log, const char *file, int line, const char *func) { if (!log) { log = zt_log_logger(NULL); } log->file = (char *)file; log->line = line; log->function = (char *)func; }
unsigned int zt_log_set_opts(zt_log_ty *log, unsigned int opts) { unsigned int oopts; if (!log) { log = zt_log_logger(NULL); } oopts = log->opts; log->opts = opts; return oopts; }
zt_log_level zt_log_set_level(zt_log_ty *log, zt_log_level level) { zt_log_level olevel; if (!log) { log = zt_log_logger(NULL); } olevel = log->level; log->level = level; return olevel; }
void zt_log_lvprintf(zt_log_ty *log, zt_log_level level, char *fmt, va_list ap) { if (!log) { log = zt_log_logger(NULL); } if (level > log->level) { return; } if (log->vtbl->print) { log->vtbl->print(log, level, fmt, ap); } zt_log_set_debug_info(log, NULL, -1, NULL); }
void zt_log_lprintf(zt_log_ty *log, zt_log_level level, char *fmt, ...) { va_list ap; if (!log) { log = zt_log_logger(NULL); } if (level > log->level) { return; } va_start(ap, fmt); zt_log_lvprintf(log, level, fmt, ap); va_end(ap); }