Changeset 189 for branches/client-1.5/src/debug.c
- Timestamp:
- May 12, 2009, 8:09:42 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/client-1.5/src/debug.c
r188 r189 28 28 #include <sys/types.h> 29 29 #include <sys/time.h> 30 #include <sys/stat.h> 30 31 31 // #include "smbwrp.h" 32 33 int debuglevel = 0; 34 char *logfile = NULL; 35 36 37 void dbgfileinit(char *file, int loglevel) 38 { 39 logfile = file; 40 debuglevel = loglevel; 41 } 32 int debuglevel = 9; // we set it to 9, so we get all messages 33 char logfile[_MAX_PATH +1] = {0}; 34 char debugfile[_MAX_PATH +1] = {0}; 35 char logfilename[] = "ndpsmb.log"; 42 36 43 37 int debuglvl(int level) … … 46 40 } 47 41 48 int debugheader(int level, char * file, char * func, int line)49 {50 int rc;51 if (!debuglvl(level))52 {53 return 0;54 }55 rc = 1;56 do57 {58 FILE * f;59 struct timeval tv;60 time_t t;61 char buf[80] = {0};62 if (logfile)63 {64 f = fopen(logfile, "a");65 if (!f)66 {67 rc = 0;68 break;69 }70 }71 else72 {73 f = stdout;74 }75 gettimeofday(&tv, NULL);76 t = time(NULL);77 strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime(&t));78 fprintf(f, "%s.%d: %d %d: %s:%s(%d) :", buf, tv.tv_usec / 10000, level, (long)_gettid(), file, func, line);79 if (logfile)80 {81 fclose(f);82 }83 }84 while (0);85 return rc;86 }87 88 int debugmessage(char * fmt, ...)89 {90 do91 {92 FILE * f;93 va_list args;94 if (logfile)95 {96 f = fopen(logfile, "a");97 if (!f)98 {99 break;100 }101 }102 else103 {104 f = stdout;105 }106 va_start(args, fmt);107 vfprintf(f, fmt, args);108 va_end(args);109 if (logfile)110 {111 fclose(f);112 }113 }114 while (0);115 return 0;116 }117 118 42 void debuglocal(int level, const char * fmt, ...) 119 43 { 44 FILE *f=NULL; 45 struct stat filestat; 46 47 // if the file ndpsmb.dbg is around we write a logfile 48 if (!debugfile[0]) 49 { 50 strncpy(debugfile, getenv("ETC"), 2); 51 strncat(debugfile, "\\", sizeof(debugfile) - strlen(debugfile) -1); 52 strncat(debugfile, "ndpsmb.dbg", sizeof(debugfile) - strlen(debugfile) -1); 53 } /* endif */ 54 55 if (stat(debugfile, &filestat) !=0) 56 return; 57 58 //we create the logfile variable only once 59 if (!logfile[0]) 60 { 61 char *env = getenv("LOGFILES"); 62 if (env != NULL) 63 { 64 strncpy(logfile, env, sizeof(logfile) -1); 65 strncat(logfile, "\\", sizeof(logfile) - strlen(logfile) -1); 66 strncat(logfile, logfilename, sizeof(logfile) - strlen(logfile) -1); 67 } 68 else 69 { 70 strncpy(logfile, logfilename, sizeof(logfile) -1); 71 } 72 } /* endif */ 120 73 121 74 if (!debuglvl(level)) … … 125 78 do 126 79 { 127 FILE * f;128 80 struct timeval tv; 129 81 char buf[80] = {0}; 130 82 va_list args; 131 if (logfile )83 if (logfile[0]) 132 84 { 133 85 f = fopen(logfile, "a");
Note:
See TracChangeset
for help on using the changeset viewer.