Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/utils.c @ 378:2e6c7b1440d1
Improve debugging/logging
* Tell the user when the tracelog file can't be open
* Only include logprint.h when screen.h is not needed
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Tue, 26 Jul 2005 18:33:22 +0100 |
parents | bd5638c21834 |
children | f8f3c7493457 |
comparison
equal
deleted
inserted
replaced
377:00809e3e327e | 378:2e6c7b1440d1 |
---|---|
29 #include <unistd.h> | 29 #include <unistd.h> |
30 #include <sys/types.h> | 30 #include <sys/types.h> |
31 #include <sys/stat.h> | 31 #include <sys/stat.h> |
32 | 32 |
33 #include <config.h> | 33 #include <config.h> |
34 #include "screen.h" | 34 #include "logprint.h" |
35 | 35 |
36 static int DebugEnabled; | 36 static int DebugEnabled; |
37 static char *FName; | 37 static char *FName; |
38 | 38 |
39 void ut_InitDebug(unsigned int level, const char *filename) | 39 void ut_InitDebug(unsigned int level, const char *filename) |
61 } | 61 } |
62 | 62 |
63 DebugEnabled = level; | 63 DebugEnabled = level; |
64 | 64 |
65 fp = fopen(FName, "a"); | 65 fp = fopen(FName, "a"); |
66 if (!fp) return; | 66 if (!fp) { |
67 fprintf(stderr, "ERROR: Cannot open tracelog file\n"); | |
68 return; | |
69 } | |
67 fprintf(fp, "New trace log started.\n" | 70 fprintf(fp, "New trace log started.\n" |
68 "----------------------\n"); | 71 "----------------------\n"); |
69 fchmod(fileno(fp), S_IRUSR|S_IWUSR); | 72 fchmod(fileno(fp), S_IRUSR|S_IWUSR); |
70 fclose(fp); | 73 fclose(fp); |
71 } | 74 } |
75 if (!DebugEnabled || !FName) return; | 78 if (!DebugEnabled || !FName) return; |
76 | 79 |
77 if (((DebugEnabled == 2) && (flag & (LPRINT_LOG|LPRINT_DEBUG))) || | 80 if (((DebugEnabled == 2) && (flag & (LPRINT_LOG|LPRINT_DEBUG))) || |
78 ((DebugEnabled == 1) && (flag & LPRINT_LOG))) { | 81 ((DebugEnabled == 1) && (flag & LPRINT_LOG))) { |
79 FILE *fp = fopen(FName, "a+"); | 82 FILE *fp = fopen(FName, "a+"); |
80 if (!fp) return; | 83 if (!fp) { |
84 scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot open tracelog file"); | |
85 return; | |
86 } | |
81 fputs(data, fp); | 87 fputs(data, fp); |
82 fclose(fp); | 88 fclose(fp); |
83 } | 89 } |
84 } | 90 } |
85 | 91 |