Mercurial > pidgin.yaz
comparison src/log.c @ 11292:ef9280fdc511
[gaim-migrate @ 13492]
Apparently, users like to know when logging is failing. Who knew?
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 18 Aug 2005 04:14:07 +0000 |
parents | bb0d7b719af2 |
children | 4db38b374d3f |
comparison
equal
deleted
inserted
replaced
11291:57fccea36e36 | 11292:ef9280fdc511 |
---|---|
47 | 47 |
48 /************************************************************************** | 48 /************************************************************************** |
49 * PUBLIC LOGGING FUNCTIONS *********************************************** | 49 * PUBLIC LOGGING FUNCTIONS *********************************************** |
50 **************************************************************************/ | 50 **************************************************************************/ |
51 | 51 |
52 GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account, time_t time) | 52 GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account, |
53 GaimConversation *conv, time_t time) | |
53 { | 54 { |
54 GaimLog *log = g_new0(GaimLog, 1); | 55 GaimLog *log = g_new0(GaimLog, 1); |
55 log->name = g_strdup(gaim_normalize(account, name)); | 56 log->name = g_strdup(gaim_normalize(account, name)); |
56 log->account = account; | 57 log->account = account; |
58 log->conv = conv; | |
57 log->time = time; | 59 log->time = time; |
58 log->type = type; | 60 log->type = type; |
59 log->logger_data = NULL; | 61 log->logger_data = NULL; |
60 log->logger = gaim_log_logger_get(); | 62 log->logger = gaim_log_logger_get(); |
61 if (log->logger && log->logger->create) | 63 if (log->logger && log->logger->create) |
454 | 456 |
455 /**************************************************************************** | 457 /**************************************************************************** |
456 * LOGGERS ****************************************************************** | 458 * LOGGERS ****************************************************************** |
457 ****************************************************************************/ | 459 ****************************************************************************/ |
458 | 460 |
459 void gaim_log_common_writer(GaimLog *log, time_t time, const char *ext) | 461 void gaim_log_common_writer(GaimLog *log, const char *ext) |
460 { | 462 { |
461 char date[64]; | 463 char date[64]; |
462 GaimLogCommonLoggerData *data = log->logger_data; | 464 GaimLogCommonLoggerData *data = log->logger_data; |
463 | 465 |
464 if(!data) { | 466 if (data == NULL) |
467 { | |
465 /* This log is new */ | 468 /* This log is new */ |
466 char *dir, *filename, *path; | 469 char *dir, *filename, *path; |
467 | 470 |
468 dir = gaim_log_get_log_dir(log->type, log->name, log->account); | 471 dir = gaim_log_get_log_dir(log->type, log->name, log->account); |
469 if (dir == NULL) | 472 if (dir == NULL) |
480 g_free(filename); | 483 g_free(filename); |
481 | 484 |
482 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1); | 485 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1); |
483 | 486 |
484 data->file = g_fopen(path, "a"); | 487 data->file = g_fopen(path, "a"); |
485 if (!data->file) { | 488 if (data->file == NULL) |
489 { | |
486 gaim_debug(GAIM_DEBUG_ERROR, "log", | 490 gaim_debug(GAIM_DEBUG_ERROR, "log", |
487 "Could not create log file %s\n", path); | 491 "Could not create log file %s\n", path); |
492 | |
493 if (log->conv != NULL) | |
494 gaim_conversation_write(log->conv, NULL, _("Logging of this conversation failed."), | |
495 GAIM_MESSAGE_ERROR, time(NULL)); | |
496 | |
488 g_free(path); | 497 g_free(path); |
489 return; | 498 return; |
490 } | 499 } |
491 g_free(path); | 500 g_free(path); |
492 } | 501 } |
516 strlen(filename) == 17 + strlen(ext)) { | 525 strlen(filename) == 17 + strlen(ext)) { |
517 GaimLog *log; | 526 GaimLog *log; |
518 GaimLogCommonLoggerData *data; | 527 GaimLogCommonLoggerData *data; |
519 time_t stamp = gaim_str_to_time(filename, FALSE); | 528 time_t stamp = gaim_str_to_time(filename, FALSE); |
520 | 529 |
521 log = gaim_log_new(type, name, account, stamp); | 530 log = gaim_log_new(type, name, account, NULL, stamp); |
522 log->logger = logger; | 531 log->logger = logger; |
523 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1); | 532 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1); |
524 data->path = g_build_filename(path, filename, NULL); | 533 data->path = g_build_filename(path, filename, NULL); |
525 list = g_list_append(list, log); | 534 list = g_list_append(list, log); |
526 } | 535 } |
767 GaimLogCommonLoggerData *data = log->logger_data; | 776 GaimLogCommonLoggerData *data = log->logger_data; |
768 | 777 |
769 if(!data) { | 778 if(!data) { |
770 const char *prpl = | 779 const char *prpl = |
771 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); | 780 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); |
772 gaim_log_common_writer(log, time, ".html"); | 781 gaim_log_common_writer(log, ".html"); |
773 | 782 |
774 data = log->logger_data; | 783 data = log->logger_data; |
775 | 784 |
776 /* if we can't write to the file, give up before we hurt ourselves */ | 785 /* if we can't write to the file, give up before we hurt ourselves */ |
777 if(!data->file) | 786 if(!data->file) |
908 * creating a new file there would result in empty files in the case | 917 * creating a new file there would result in empty files in the case |
909 * that you open a convo with someone, but don't say anything. | 918 * that you open a convo with someone, but don't say anything. |
910 */ | 919 */ |
911 const char *prpl = | 920 const char *prpl = |
912 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); | 921 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); |
913 gaim_log_common_writer(log, time, ".txt"); | 922 gaim_log_common_writer(log, ".txt"); |
914 | 923 |
915 data = log->logger_data; | 924 data = log->logger_data; |
916 | 925 |
917 /* if we can't write to the file, give up before we hurt ourselves */ | 926 /* if we can't write to the file, give up before we hurt ourselves */ |
918 if(!data->file) | 927 if(!data->file) |
1090 | 1099 |
1091 if(strchr(buf, '\r')) | 1100 if(strchr(buf, '\r')) |
1092 newlen--; | 1101 newlen--; |
1093 | 1102 |
1094 if (newlen != 0) { | 1103 if (newlen != 0) { |
1095 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1); | 1104 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1); |
1096 log->logger = &old_logger; | 1105 log->logger = &old_logger; |
1097 log->time = lasttime; | 1106 log->time = lasttime; |
1098 data = g_new0(struct old_logger_data, 1); | 1107 data = g_new0(struct old_logger_data, 1); |
1099 data->offset = lastoff; | 1108 data->offset = lastoff; |
1100 data->length = newlen; | 1109 data->length = newlen; |
1141 } | 1150 } |
1142 } | 1151 } |
1143 | 1152 |
1144 if (logfound) { | 1153 if (logfound) { |
1145 if ((newlen = ftell(file) - lastoff) != 0) { | 1154 if ((newlen = ftell(file) - lastoff) != 0) { |
1146 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1); | 1155 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1); |
1147 log->logger = &old_logger; | 1156 log->logger = &old_logger; |
1148 log->time = lasttime; | 1157 log->time = lasttime; |
1149 data = g_new0(struct old_logger_data, 1); | 1158 data = g_new0(struct old_logger_data, 1); |
1150 data->offset = lastoff; | 1159 data->offset = lastoff; |
1151 data->length = newlen; | 1160 data->length = newlen; |