As a precaution, set some pointers to NULL after free
[flog.git] / test.c
blob5feefdec85b440c64a8ae7733533e89c4ce5cd23
1 #include "flog.h"
2 #include "flog_stdio.h"
3 #include "flog_file.h"
4 #include <stdio.h>
5 #include <stdlib.h>
7 //simple example program
9 int main(void)
11 FLOG_T *log_main,*log_subfunc,*log_stdout,*log_stderr,*log_file;
12 printf("-[flog test start]-\n");
14 //create logs
15 log_main = create_flog_t(__func__,FLOG_ACCEPT_ALL);
16 log_subfunc = create_flog_t("subfunc",FLOG_ACCEPT_ALL);
17 log_stdout = create_flog_t("stdout",FLOG_ACCEPT_ONLY_ERROR);
18 log_stderr = create_flog_t("stderr",FLOG_ACCEPT_ALL);
19 log_file = create_flog_t("file",FLOG_ACCEPT_ALL);
21 //set error logs
22 log_main->error_log=log_main;
23 log_subfunc->error_log=log_main;
24 log_stdout->error_log=log_main;
25 log_stderr->error_log=log_main;
26 log_file->error_log=log_main;
28 //set output functions
29 log_stdout->output_func=flog_output_stdout;
30 log_stderr->output_func=flog_output_stderr;
31 log_file->output_func=flog_output_file;
33 //append them to eachother
34 flog_append_sublog(log_subfunc,log_main);
35 flog_append_sublog(log_main,log_stdout);
36 flog_append_sublog(log_main,log_stderr);
37 flog_append_sublog(log_main,log_file);
39 flog_print(log_subfunc,FLOG_ERROR,"print_test","testing...");
40 flog_printf(log_subfunc,FLOG_INFO,"printf_test","testing... %d %d %d",1,2,3);
42 flog_assert(log_subfunc,1+1);
43 flog_assert(log_subfunc,1-1);
45 #ifdef DEBUG
46 printf("-[flog test suite]-\n");
47 flog_test(log_main);
48 #endif
50 //clean up
51 destroy_flog_t(log_subfunc);
52 destroy_flog_t(log_main);
53 destroy_flog_t(log_stdout);
54 destroy_flog_t(log_stderr);
55 destroy_flog_t(log_file);
56 return(0);