Makefile: add test.o to clean
[flog.git] / flog_output_stdio.c
blobab93540c5c50903b54268353c8fee20f33a7fe25
1 //! stdio output for Flog
3 //! @file flog_output_stdio.c
4 //! @author Nabeel Sowan (nabeel.sowan@vibes.se)
5 //!
6 //! When you want flog to write to stdout or stderr
9 #include "flog_output_stdio.h"
11 #ifdef FLOG_CONFIG_OUTPUT_STDIO
13 #include "flog_string.h"
14 #include <stdlib.h>
15 #include <stdio.h>
18 //! Output function for log output to stdout
20 //! @retval 0 success
21 int flog_output_stdout(FLOG_T *log,const FLOG_MSG_T *msg)
23 char *str;
24 if(flog_get_str_message(&str,msg))
25 return(-1);
26 if(fprintf(stdout,str)<0) {
27 log->output_error=1;
28 free(str);
29 flog_print(log->error_log,NULL,FLOG_ERROR,FLOG_MSG_CANNOT_WRITE_TO_STDOUT,NULL);
30 return(-2);
32 free(str);
33 return(0);
37 //! Output function for log output to stderr
39 //! @retval 0 success
40 int flog_output_stderr(FLOG_T *log,const FLOG_MSG_T *msg)
42 char *str;
43 if(flog_get_str_message(&str,msg))
44 return(-1);
45 if(fprintf(stderr,str)<0) {
46 log->output_error=1;
47 free(str);
48 flog_print(log->error_log,NULL,FLOG_ERROR,FLOG_MSG_CANNOT_WRITE_TO_STDERR,NULL);
49 return(-2);
51 free(str);
52 return(0);
56 //! create and return a log that writes to stdout
58 //! @retval NULL error
59 FLOG_T * create_flog_output_stdout(const char *name, FLOG_MSG_TYPE_T accepted_msg_type)
61 FLOG_T *p;
62 if((p=create_flog_t(name,accepted_msg_type))==NULL)
63 return(NULL);
64 p->output_func=flog_output_stdout;
65 return(p);
69 //! create and return a log that writes to stderr
71 //! @retval NULL error
72 FLOG_T * create_flog_output_stderr(const char *name, FLOG_MSG_TYPE_T accepted_msg_type)
74 FLOG_T *p;
75 if((p=create_flog_t(name,accepted_msg_type))==NULL)
76 return(NULL);
77 p->output_func=flog_output_stderr;
78 return(p);
82 #endif //FLOG_CONFIG_OUTPUT_STDIO