diff --git a/src/example/example.c b/src/example/example.c index 640b405..b96ebdf 100644 --- a/src/example/example.c +++ b/src/example/example.c @@ -5,20 +5,22 @@ extern const char *level_strings[]; void callback1(log_Event *ev) { - char logline[128]; - snprintf(logline, 128, "%-5s %s:%d: ", - level_strings[ev->level], ev->file, ev->line); - vsnprintf(logline, 128, ev->fmt, ev->ap); - printf("%s: %s\n", __func__, logline); + char buf[16]; + buf[strftime(buf, sizeof(buf), "%H:%M:%S", ev->time)] = '\0'; + fprintf(stdout, "callback 1 %s %-5s %s:%d: ", buf, level_strings[ev->level], ev->file, ev->line); + vfprintf(stdout, ev->fmt, ev->ap); + fprintf(stdout, "\n"); + fflush(stdout); } void callback2(log_Event *ev) { - char logline[128]; - snprintf(logline, 128, "%-5s %s:%d: ", - level_strings[ev->level], ev->file, ev->line); - vsnprintf(logline, 128, ev->fmt, ev->ap); - printf("%s: %s\n", __func__, logline); + char buf[16]; + buf[strftime(buf, sizeof(buf), "%H:%M:%S", ev->time)] = '\0'; + fprintf(stdout, "callback 2 %s %-5s %s:%d: ", buf, level_strings[ev->level], ev->file, ev->line); + vfprintf(stdout, ev->fmt, ev->ap); + fprintf(stdout, "\n"); + fflush(stdout); } int main() @@ -29,7 +31,7 @@ int main() log_warn("hello"); log_error("hello"); log_fatal("hello"); - log_debug("============== update loglevel to FATAL ============="); + printf("============== update loglevel to FATAL =============\n"); log_set_level(LOG_FATAL); log_trace("hello"); log_debug("hello"); @@ -37,7 +39,7 @@ int main() log_warn("hello"); log_error("hello"); log_fatal("hello"); - log_debug("===================== init log ====================="); + printf("===================== add callback =================\n"); log_add_callback(callback1, "progname", LOG_TRACE); log_add_callback(callback2, "progname", LOG_TRACE); log_trace("hello"); @@ -46,8 +48,14 @@ int main() log_warn("hello"); log_error("hello"); log_fatal("hello"); - log_debug("============ update loglevels of callbacks ========"); + printf("============ update loglevels of callbacks ========\n"); log_set_level_callback(callback1, LOG_FATAL); log_set_level_callback(callback2, LOG_WARN); + log_trace("hello"); + log_debug("hello"); + log_info("hello"); + log_warn("hello"); + log_error("hello"); + log_fatal("hello"); return 0; } \ No newline at end of file