Changeset 1074 in MondoRescue for trunk/mondo/src/lib/mr_msg.c
- Timestamp:
- Jan 25, 2007, 4:18:12 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/src/lib/mr_msg.c
r900 r1074 10 10 */ 11 11 12 #ifndef _GNU_SOURCE 13 #define _GNU_SOURCE 14 #endif 12 15 #include <stdio.h> 13 16 #include <stdarg.h> 17 #include <stdlib.h> 14 18 15 19 static int mr_loglevel = 0; 16 20 static char *mr_logfile = NULL; 17 21 22 /* 23 * This function is in the lowest part of the tree 24 * It should not depend on any other function of the mr lib 25 */ 26 27 /* Cleanup function for messages */ 28 void mr_msg_close(void) { 29 free(mr_logfile); 30 mr_logfile = NULL; 31 mr_loglevel = 0; 32 } 33 18 34 /* Initialization function for messages */ 19 void mr_msg_init(void) { 35 void mr_msg_init(const char *configfile, int loglevel) { 36 FILE *fout = NULL; 37 int res = 0; 20 38 39 asprintf(&mr_logfile,configfile); 40 if ((fout = fopen(mr_logfile, "w")) == NULL) { 41 fprintf(stderr,"Unable to write to %s\n",mr_logfile); 42 fprintf(stderr,"Logging desactivated\n"); 43 mr_msg_close(); 44 } 45 if ((res = fclose(fout)) != 0) { 46 fprintf(stderr,"Unable to close %s\n",mr_logfile); 47 } 48 mr_loglevel = loglevel; 21 49 } 22 50 23 51 /* 24 52 * Function that log a message. Not called directly 25 * but through macros in mr_msg.h53 * but through other functions 26 54 */ 27 void _mr_msg(int debug, const char *file, const char *function, int line, const char *fmt, ...) {55 void mr_msg(int debug, const char *fmt, ...) { 28 56 29 va_list args;30 57 int i = 0; 31 58 int res = 0; 32 59 FILE *fout = NULL; 60 va_list args; 61 62 if (mr_logfile == NULL) { 63 return; 64 } 33 65 34 66 if (debug <= mr_loglevel) { 35 va_start(args, fmt); 36 if (!(fout = fopen(mr_logfile, "a"))) { 67 if ((fout = fopen(mr_logfile, "a")) == NULL) { 37 68 fprintf(stderr,"Unable to append to %s\n",mr_logfile); 38 69 return; … … 43 74 for (i = 1; i < debug; i++) 44 75 fprintf(fout, " "); 45 fprintf(fout, "%s->%s#%d: ", file, function, line);76 fprintf(fout, "%s->%s#%d: ", __FILE__, __FUNCTION__, __LINE__); 46 77 } 47 vfprintf(fout, fmt, args); 78 va_start(args,fmt); 79 if (vfprintf(fout, fmt, args) < 0) { 80 fprintf(stderr,"Unable to print to %s\n",mr_logfile); 81 } 82 va_end(args); 48 83 49 va_end(args);50 fprintf(fout, "\n");51 84 if ((res = fclose(fout)) != 0) { 52 85 fprintf(stderr,"Unable to close %s\n",mr_logfile);
Note:
See TracChangeset
for help on using the changeset viewer.