comparison mcabber/src/screen.c @ 858:2683ad5d1003

Improve scr_LogPrint() for log/debug messages
author Mikael Berthe <mikael@lilotux.net>
date Mon, 15 May 2006 23:20:59 +0200
parents ef35a2bb40d7
children cee8d6be04e1
comparison
equal deleted inserted replaced
857:ef35a2bb40d7 858:2683ad5d1003
338 // This function will convert from UTF-8 unless the LPRINT_NOTUTF8 flag is set. 338 // This function will convert from UTF-8 unless the LPRINT_NOTUTF8 flag is set.
339 void scr_LogPrint(unsigned int flag, const char *fmt, ...) 339 void scr_LogPrint(unsigned int flag, const char *fmt, ...)
340 { 340 {
341 time_t timestamp; 341 time_t timestamp;
342 char strtimestamp[64]; 342 char strtimestamp[64];
343 char *buffer, *b2; 343 char *buffer, *btext;
344 va_list ap; 344 va_list ap;
345 345
346 if (!(flag & ~LPRINT_NOTUTF8)) return; // Shouldn't happen 346 if (!(flag & ~LPRINT_NOTUTF8)) return; // Shouldn't happen
347 347
348 timestamp = time(NULL); 348 timestamp = time(NULL);
349 strftime(strtimestamp, 48, "[%H:%M:%S]", localtime(&timestamp)); 349 strftime(strtimestamp, 48, "[%H:%M:%S]", localtime(&timestamp));
350 va_start(ap, fmt); 350 va_start(ap, fmt);
351 b2 = g_strdup_vprintf(fmt, ap); 351 btext = g_strdup_vprintf(fmt, ap);
352 va_end(ap); 352 va_end(ap);
353
354 buffer = g_strdup_printf("%s %s", strtimestamp, b2);
355 353
356 if (flag & LPRINT_NORMAL) { 354 if (flag & LPRINT_NORMAL) {
357 char *buffer_locale; 355 char *buffer_locale;
358 char *buf_specialwindow; 356 char *buf_specialwindow;
357
358 buffer = g_strdup_printf("%s %s", strtimestamp, btext);
359 359
360 // Convert buffer to current locale for wprintw() 360 // Convert buffer to current locale for wprintw()
361 if (!(flag & LPRINT_NOTUTF8)) 361 if (!(flag & LPRINT_NOTUTF8))
362 buffer_locale = from_utf8(buffer); 362 buffer_locale = from_utf8(buffer);
363 else 363 else
364 buffer_locale = buffer; 364 buffer_locale = buffer;
365 365
366 // For the special status buffer, we need utf-8, but without the timestamp 366 // For the special status buffer, we need utf-8, but without the timestamp
367 if (flag & LPRINT_NOTUTF8) 367 if (flag & LPRINT_NOTUTF8)
368 buf_specialwindow = to_utf8(b2); 368 buf_specialwindow = to_utf8(btext);
369 else 369 else
370 buf_specialwindow = b2; 370 buf_specialwindow = btext;
371 371
372 if (Curses) { 372 if (Curses) {
373 wprintw(logWnd, "\n%s", buffer_locale); 373 wprintw(logWnd, "\n%s", buffer_locale);
374 update_panels(); 374 update_panels();
375 doupdate(); 375 doupdate();
380 // ncurses are not initialized yet, so we call directly hbuf routine 380 // ncurses are not initialized yet, so we call directly hbuf routine
381 hbuf_add_line(&statushbuf, buf_specialwindow, timestamp, 381 hbuf_add_line(&statushbuf, buf_specialwindow, timestamp,
382 HBB_PREFIX_SPECIAL, 0); 382 HBB_PREFIX_SPECIAL, 0);
383 } 383 }
384 384
385 if (buf_specialwindow != b2) 385 if (buf_specialwindow != btext)
386 g_free(buf_specialwindow); 386 g_free(buf_specialwindow);
387 if (!(flag & LPRINT_NOTUTF8)) 387 if (!(flag & LPRINT_NOTUTF8))
388 g_free(buffer_locale); 388 g_free(buffer_locale);
389 } 389
390 g_free(buffer); 390 g_free(buffer);
391 }
391 392
392 if (flag & (LPRINT_LOG|LPRINT_DEBUG)) { 393 if (flag & (LPRINT_LOG|LPRINT_DEBUG)) {
393 strftime(strtimestamp, 23, "[%Y-%m-%d %H:%M:%S]", localtime(&timestamp)); 394 strftime(strtimestamp, 23, "[%Y-%m-%d %H:%M:%S]", localtime(&timestamp));
394 buffer = g_strdup_printf("%s %s\n", strtimestamp, b2); 395 buffer = g_strdup_printf("%s %s\n", strtimestamp, btext);
395 ut_WriteLog(flag, buffer); 396 ut_WriteLog(flag, buffer);
396 g_free(buffer); 397 g_free(buffer);
397 } 398 }
398 } 399 }
399 400