Change text output format again
[flog.git] / flog_file.c
bloba56cdfbb5821b2441cdbb78e3f1ca048a1dd4fb0
1 /*!
2 @file flog_file.c
3 @brief file output for Flog
4 @author Nabeel Sowan (nabeel.sowan@vibes.se)
6 When you want flog to write to a file
7 Choose logfile name by setting data to string
8 */
10 #include "flog_file.h"
11 #include <stdlib.h>
12 #include <stdio.h>
14 int flog_output_file(FLOG_T *log,const FLOG_MSG_T *msg)
16 char *str;
17 int e=0;
18 if((str=flog_msg_t_to_str(msg))==NULL)
19 return(1);
20 if(log->output_func_data==NULL) {
21 log->output_error=1;
22 flog_print(log->error_log,FLOG_ERROR,NULL,"please set filename for flog_output_file()");
23 e=1;
24 } else {
25 FILE *f;
26 if((f = fopen(log->output_func_data,"a+t"))==NULL) {
27 log->output_error=1;
28 flog_printf(log->error_log,FLOG_ERROR,NULL,"cannot open file: %s",log->output_func_data);
29 e=1;
30 } else {
31 if(fprintf(f,str)<0) {
32 log->output_error=1;
33 flog_printf(log->error_log,FLOG_ERROR,NULL,"cannot write to file: %s",log->output_func_data);
34 e=1;
36 fclose(f);
39 free(str);
40 return(e);