Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/screen.c @ 374:bd5638c21834
Improve logging system (traces)
There are now two trace logging levels:
* tracelog_level = 1:
Most messages from the log window are written to disk (LPRINT_LOG)
* tracelog_level =2:
LPRINT_LOG & LPRINT_DEBUG messages are written to disk
The trace file name is set with the "tracelog_file" option.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 25 Jul 2005 21:46:35 +0100 |
parents | af2f8ddf6a1b |
children | 4c6e8392e465 d59e9b8c91d3 |
comparison
equal
deleted
inserted
replaced
373:af2f8ddf6a1b | 374:bd5638c21834 |
---|---|
231 return; | 231 return; |
232 } | 232 } |
233 | 233 |
234 // scr_LogPrint(...) | 234 // scr_LogPrint(...) |
235 // Display a message in the log window. | 235 // Display a message in the log window. |
236 void scr_LogPrint(const char *fmt, ...) | 236 void scr_LogPrint(unsigned int flag, const char *fmt, ...) |
237 { | 237 { |
238 time_t timestamp; | 238 time_t timestamp; |
239 char *buffer; | 239 char *buffer, *b2; |
240 va_list ap; | 240 va_list ap; |
241 | 241 |
242 if (!flag) return; | |
243 | |
242 do { | 244 do { |
243 buffer = (char *) calloc(1, 1024); | 245 buffer = (char *) calloc(1, 1088); |
244 } while (!buffer); | 246 } while (!buffer); |
245 | 247 |
246 timestamp = time(NULL); | 248 timestamp = time(NULL); |
247 strftime(buffer, 64, "[%H:%M:%S] ", localtime(×tamp)); | 249 strftime(buffer, 64, "[%H:%M:%S] ", localtime(×tamp)); |
248 if (Curses) | 250 for (b2 = buffer ; *b2 ; b2++) |
249 wprintw(logWnd, "\n%s", buffer); | 251 ; |
250 else | |
251 printf("%s", buffer); | |
252 | |
253 va_start(ap, fmt); | 252 va_start(ap, fmt); |
254 vsnprintf(buffer, 1024, fmt, ap); | 253 vsnprintf(b2, 1024, fmt, ap); |
255 va_end(ap); | 254 va_end(ap); |
256 | 255 |
257 if (Curses) { | 256 if (flag & LPRINT_NORMAL) { |
258 wprintw(logWnd, "%s", buffer); | 257 if (Curses) { |
259 update_panels(); | 258 wprintw(logWnd, "\n%s", buffer); |
260 doupdate(); | 259 update_panels(); |
261 } else { | 260 doupdate(); |
262 printf("%s\n", buffer); | 261 } else { |
262 printf("%s\n", buffer); | |
263 } | |
264 } | |
265 if (flag & (LPRINT_LOG|LPRINT_DEBUG)) { | |
266 strcat(buffer, "\n"); | |
267 ut_WriteLog(flag, buffer); | |
263 } | 268 } |
264 free(buffer); | 269 free(buffer); |
265 } | 270 } |
266 | 271 |
267 static window_entry_t *scr_CreateBuddyPanel(const char *title, int dont_show) | 272 static window_entry_t *scr_CreateBuddyPanel(const char *title, int dont_show) |
577 logPanel_border = new_panel(logWnd_border); | 582 logPanel_border = new_panel(logWnd_border); |
578 logPanel = new_panel(logWnd); | 583 logPanel = new_panel(logWnd); |
579 inputPanel = new_panel(inputWnd); | 584 inputPanel = new_panel(inputWnd); |
580 | 585 |
581 if (utf8_mode) | 586 if (utf8_mode) |
582 scr_LogPrint("WARNING: UTF-8 not yet supported!"); | 587 scr_LogPrint(LPRINT_NORMAL, "WARNING: UTF-8 not yet supported!"); |
583 } else { | 588 } else { |
584 // Update panels | 589 // Update panels |
585 replace_panel(rosterPanel, rosterWnd); | 590 replace_panel(rosterPanel, rosterWnd); |
586 replace_panel(chatPanel, chatWnd); | 591 replace_panel(chatPanel, chatWnd); |
587 replace_panel(logPanel, logWnd); | 592 replace_panel(logPanel, logWnd); |
680 } | 685 } |
681 | 686 |
682 // Update offset if necessary | 687 // Update offset if necessary |
683 i = g_list_position(buddylist, current_buddy); | 688 i = g_list_position(buddylist, current_buddy); |
684 if (i == -1) { // This is bad | 689 if (i == -1) { // This is bad |
685 scr_LogPrint("Doh! Can't find current selected buddy!!"); | 690 scr_LogPrint(LPRINT_NORMAL, "Doh! Can't find current selected buddy!!"); |
686 return; | 691 return; |
687 } else if (i < offset) { | 692 } else if (i < offset) { |
688 offset = i; | 693 offset = i; |
689 } else if (i+1 > offset + maxy) { | 694 } else if (i+1 > offset + maxy) { |
690 offset = i + 1 - maxy; | 695 offset = i + 1 - maxy; |
918 | 923 |
919 nbuddy = g_list_find(buddylist, unread_ptr); | 924 nbuddy = g_list_find(buddylist, unread_ptr); |
920 if (nbuddy) { | 925 if (nbuddy) { |
921 set_current_buddy(nbuddy); | 926 set_current_buddy(nbuddy); |
922 if (chatmode) scr_ShowBuddyWindow(); | 927 if (chatmode) scr_ShowBuddyWindow(); |
923 } else scr_LogPrint("Error: nbuddy == NULL"); | 928 } else |
929 scr_LogPrint(LPRINT_LOGNORM, "Error: nbuddy == NULL"); // should not happen | |
924 } | 930 } |
925 | 931 |
926 // scr_RosterJumpAlternate() | 932 // scr_RosterJumpAlternate() |
927 // Try to jump to alternate (== previous) buddy | 933 // Try to jump to alternate (== previous) buddy |
928 void scr_RosterJumpAlternate(void) | 934 void scr_RosterJumpAlternate(void) |
1059 | 1065 |
1060 // Finished :) | 1066 // Finished :) |
1061 update_panels(); | 1067 update_panels(); |
1062 doupdate(); | 1068 doupdate(); |
1063 } else | 1069 } else |
1064 scr_LogPrint("Search string not found"); | 1070 scr_LogPrint(LPRINT_NORMAL, "Search string not found"); |
1065 } | 1071 } |
1066 | 1072 |
1067 // scr_set_chatmode() | 1073 // scr_set_chatmode() |
1068 // Public function to (un)set chatmode... | 1074 // Public function to (un)set chatmode... |
1069 inline void scr_set_chatmode(int enable) | 1075 inline void scr_set_chatmode(int enable) |
1107 void scr_append_multiline(const char *line) | 1113 void scr_append_multiline(const char *line) |
1108 { | 1114 { |
1109 static int num; | 1115 static int num; |
1110 | 1116 |
1111 if (!multimode) { | 1117 if (!multimode) { |
1112 scr_LogPrint("Error: Not in multi-line message mode!"); | 1118 scr_LogPrint(LPRINT_NORMAL, "Error: Not in multi-line message mode!"); |
1113 return; | 1119 return; |
1114 } | 1120 } |
1115 if (multiline) { | 1121 if (multiline) { |
1116 int len = strlen(multiline)+strlen(line)+2; | 1122 int len = strlen(multiline)+strlen(line)+2; |
1117 if (len >= HBB_BLOCKSIZE - 1) { | 1123 if (len >= HBB_BLOCKSIZE - 1) { |
1118 // We don't handle single messages with size > HBB_BLOCKSIZE | 1124 // We don't handle single messages with size > HBB_BLOCKSIZE |
1119 // (see hbuf) | 1125 // (see hbuf) |
1120 scr_LogPrint("Your multi-line message is too big, this line has " | 1126 scr_LogPrint(LPRINT_NORMAL, "Your multi-line message is too big, " |
1121 "not been added."); | 1127 "this line has not been added."); |
1122 scr_LogPrint("Please send this part now..."); | 1128 scr_LogPrint(LPRINT_NORMAL, "Please send this part now..."); |
1123 return; | 1129 return; |
1124 } | 1130 } |
1125 if (num >= MULTILINE_MAX_LINE_NUMBER) { | 1131 if (num >= MULTILINE_MAX_LINE_NUMBER) { |
1126 // We don't allow too many lines; however the maximum is arbitrary | 1132 // We don't allow too many lines; however the maximum is arbitrary |
1127 // (It should be < 1000 yet) | 1133 // (It should be < 1000 yet) |
1128 scr_LogPrint("Your message has too many lines, this one has " | 1134 scr_LogPrint(LPRINT_NORMAL, "Your message has too many lines, " |
1129 "not been added."); | 1135 "this one has not been added."); |
1130 scr_LogPrint("Please send this part now..."); | 1136 scr_LogPrint(LPRINT_NORMAL, "Please send this part now..."); |
1131 return; | 1137 return; |
1132 } | 1138 } |
1133 multiline = g_renew(char, multiline, len); | 1139 multiline = g_renew(char, multiline, len); |
1134 strcat(multiline, "\n"); | 1140 strcat(multiline, "\n"); |
1135 strcat(multiline, line); | 1141 strcat(multiline, line); |
1142 strcpy(multiline, line); | 1148 strcpy(multiline, line); |
1143 num++; | 1149 num++; |
1144 } else | 1150 } else |
1145 return; | 1151 return; |
1146 } | 1152 } |
1147 scr_LogPrint("Multi-line mode: line #%d added [%.25s...", num, line); | 1153 scr_LogPrint(LPRINT_NORMAL, "Multi-line mode: line #%d added [%.25s...", |
1154 num, line); | |
1148 } | 1155 } |
1149 | 1156 |
1150 // scr_cmdhisto_addline() | 1157 // scr_cmdhisto_addline() |
1151 // Add a line to the inputLine history | 1158 // Add a line to the inputLine history |
1152 inline void scr_cmdhisto_addline(char *line) | 1159 inline void scr_cmdhisto_addline(char *line) |
1298 { | 1305 { |
1299 char tmpLine[INPUTLINE_LENGTH+1]; | 1306 char tmpLine[INPUTLINE_LENGTH+1]; |
1300 int len = strlen(text); | 1307 int len = strlen(text); |
1301 // Check the line isn't too long | 1308 // Check the line isn't too long |
1302 if (strlen(inputLine) + len >= INPUTLINE_LENGTH) { | 1309 if (strlen(inputLine) + len >= INPUTLINE_LENGTH) { |
1303 scr_LogPrint("Cannot insert text, line too long."); | 1310 scr_LogPrint(LPRINT_LOGNORM, "Cannot insert text, line too long."); |
1304 return; | 1311 return; |
1305 } | 1312 } |
1306 | 1313 |
1307 strcpy(tmpLine, ptr_inputline); | 1314 strcpy(tmpLine, ptr_inputline); |
1308 strcpy(ptr_inputline, text); ptr_inputline += len; | 1315 strcpy(ptr_inputline, text); ptr_inputline += len; |
1337 // This is an alias, so we can't complete rows > 0 | 1344 // This is an alias, so we can't complete rows > 0 |
1338 alias = TRUE; | 1345 alias = TRUE; |
1339 g_free(xpline); | 1346 g_free(xpline); |
1340 } | 1347 } |
1341 if ((!com && (!alias || !completion_started)) || !row) { | 1348 if ((!com && (!alias || !completion_started)) || !row) { |
1342 scr_LogPrint("I cannot complete that..."); | 1349 scr_LogPrint(LPRINT_NORMAL, "I cannot complete that..."); |
1343 return; | 1350 return; |
1344 } | 1351 } |
1345 if (!alias) | 1352 if (!alias) |
1346 compl_categ = com->completion_flags[nrow-1]; | 1353 compl_categ = com->completion_flags[nrow-1]; |
1347 else | 1354 else |
1603 scr_CheckAutoAway(TRUE); | 1610 scr_CheckAutoAway(TRUE); |
1604 if (process_command(cmd)) | 1611 if (process_command(cmd)) |
1605 return 255; | 1612 return 255; |
1606 g_free(cmd); | 1613 g_free(cmd); |
1607 } else { | 1614 } else { |
1608 scr_LogPrint("Unknown key=%d", key); | 1615 scr_LogPrint(LPRINT_NORMAL, "Unknown key=%d", key); |
1609 if (utf8_mode) | 1616 if (utf8_mode) |
1610 scr_LogPrint("WARNING: UTF-8 not yet supported!"); | 1617 scr_LogPrint(LPRINT_NORMAL, |
1618 "WARNING: UTF-8 not yet supported!"); | |
1611 } | 1619 } |
1612 } | 1620 } |
1613 } | 1621 } |
1614 } | 1622 } |
1615 if (completion_started && key != 9 && key != KEY_RESIZE) | 1623 if (completion_started && key != 9 && key != KEY_RESIZE) |