summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2019-10-06 13:36:35 +0200
committerSébastien Helleu <flashcode@flashtux.org>2019-10-06 13:36:35 +0200
commit53360a790936d558414aacd77430437403b41214 (patch)
tree5a91c14fa894816bb52c5e0a91325a5268ffc29e
parent529af3961291badcf92f51040b12bb6e1540d00f (diff)
downloadweechat-53360a790936d558414aacd77430437403b41214.zip
logger: fix write in log file if it has been deleted or renamed (closes #123)
-rw-r--r--ChangeLog.adoc1
-rw-r--r--po/cs.po6
-rw-r--r--po/de.po6
-rw-r--r--po/es.po6
-rw-r--r--po/fr.po8
-rw-r--r--po/hu.po6
-rw-r--r--po/it.po6
-rw-r--r--po/ja.po6
-rw-r--r--po/pl.po6
-rw-r--r--po/pt.po6
-rw-r--r--po/pt_BR.po6
-rw-r--r--po/ru.po6
-rw-r--r--po/tr.po6
-rw-r--r--po/weechat.pot6
-rw-r--r--src/plugins/logger/logger-buffer.c3
-rw-r--r--src/plugins/logger/logger-buffer.h4
-rw-r--r--src/plugins/logger/logger.c192
17 files changed, 199 insertions, 81 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index c4ef38542..e9ce96642 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -39,6 +39,7 @@ Bug fixes::
* buflist: fix extra spaces between buffers when conditions are used to hide buffers (regression introduced in version 2.6) (issue #1403)
* irc: remove option irc.network.channel_encode, add server option "charset_message" to control which part of the IRC message is decoded/encoded to the target charset (issue #832)
* irc: use path from option xfer.file.upload_path to complete filename in command "/dcc send" (issue #60)
+ * logger: fix write in log file if it has been deleted or renamed (issue #123)
* xfer: fix memory leak when a xfer is freed and when the plugin is unloaded
Tests::
diff --git a/po/cs.po b/po/cs.po
index 75e97bd74..92a94fa63 100644
--- a/po/cs.po
+++ b/po/cs.po
@@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
-"POT-Creation-Date: 2019-10-06 09:20+0200\n"
+"POT-Creation-Date: 2019-10-06 13:24+0200\n"
"PO-Revision-Date: 2019-05-13 21:31+0200\n"
"Last-Translator: Ondřej Súkup <mimi.vx@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -9742,6 +9742,10 @@ msgstr "%s%s: nemohu vytvořit adresář pro logy (\"%s\")"
msgid "%s%s: unable to write log file \"%s\": %s"
msgstr "%s%s: nemůžu zapsat log soubor \"%s\""
+#, fuzzy, c-format
+msgid "%s%s: unable to get file status of log file \"%s\": %s"
+msgstr "%s%s: nemůžu zapsat log soubor \"%s\""
+
#, c-format
msgid "%s\t**** Beginning of log ****"
msgstr "%s\t**** Začátek logu ****"
diff --git a/po/de.po b/po/de.po
index ccd458c34..f0252b836 100644
--- a/po/de.po
+++ b/po/de.po
@@ -24,7 +24,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
-"POT-Creation-Date: 2019-10-06 09:20+0200\n"
+"POT-Creation-Date: 2019-10-06 13:24+0200\n"
"PO-Revision-Date: 2019-10-03 15:25+0200\n"
"Last-Translator: Nils Görs <weechatter@arcor.de>\n"
"Language-Team: German <kde-i18n-de@kde.org>\n"
@@ -11559,6 +11559,10 @@ msgstr ""
msgid "%s%s: unable to write log file \"%s\": %s"
msgstr "%s%s: Protokoll-Datei \"%s\" kann nicht geschrieben werden: %s"
+#, fuzzy, c-format
+msgid "%s%s: unable to get file status of log file \"%s\": %s"
+msgstr "%s%s: Protokoll-Datei \"%s\" kann nicht geschrieben werden: %s"
+
#, c-format
msgid "%s\t**** Beginning of log ****"
msgstr "%s\t**** Beginn der Protokoll-Datei ****"
diff --git a/po/es.po b/po/es.po
index b5f33a54a..7df20e11f 100644
--- a/po/es.po
+++ b/po/es.po
@@ -22,7 +22,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
-"POT-Creation-Date: 2019-10-06 09:20+0200\n"
+"POT-Creation-Date: 2019-10-06 13:24+0200\n"
"PO-Revision-Date: 2019-05-13 21:31+0200\n"
"Last-Translator: Elián Hanisch <lambdae2@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -10052,6 +10052,10 @@ msgstr "%s%s: imposible crear directorio para registros (\"%s\")"
msgid "%s%s: unable to write log file \"%s\": %s"
msgstr "%s%s: imposible escribir en el registro \"%s\": %s"
+#, fuzzy, c-format
+msgid "%s%s: unable to get file status of log file \"%s\": %s"
+msgstr "%s%s: imposible escribir en el registro \"%s\": %s"
+
#, c-format
msgid "%s\t**** Beginning of log ****"
msgstr "%s\t**** Comienzo del registro ****"
diff --git a/po/fr.po b/po/fr.po
index 655442f7a..ea997b71f 100644
--- a/po/fr.po
+++ b/po/fr.po
@@ -21,8 +21,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
-"POT-Creation-Date: 2019-10-06 09:20+0200\n"
-"PO-Revision-Date: 2019-10-06 09:22+0200\n"
+"POT-Creation-Date: 2019-10-06 13:24+0200\n"
+"PO-Revision-Date: 2019-10-06 13:25+0200\n"
"Last-Translator: Sébastien Helleu <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"Language: fr\n"
@@ -11289,6 +11289,10 @@ msgid "%s%s: unable to write log file \"%s\": %s"
msgstr "%s%s : impossible d'écrire le fichier log \"%s\" : %s"
#, c-format
+msgid "%s%s: unable to get file status of log file \"%s\": %s"
+msgstr "%s%s : impossible de récupérer le statut du fichier de log \"%s\" : %s"
+
+#, c-format
msgid "%s\t**** Beginning of log ****"
msgstr "%s\t**** Début du log ****"
diff --git a/po/hu.po b/po/hu.po
index 4edf75458..a5c728ba9 100644
--- a/po/hu.po
+++ b/po/hu.po
@@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
-"POT-Creation-Date: 2019-10-06 09:20+0200\n"
+"POT-Creation-Date: 2019-10-06 13:24+0200\n"
"PO-Revision-Date: 2019-05-13 21:31+0200\n"
"Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -9123,6 +9123,10 @@ msgid "%s%s: unable to write log file \"%s\": %s"
msgstr "Nem sikerült a(z) \"%s\" naplófájlt írni\n"
#, fuzzy, c-format
+msgid "%s%s: unable to get file status of log file \"%s\": %s"
+msgstr "Nem sikerült a(z) \"%s\" naplófájlt írni\n"
+
+#, fuzzy, c-format
msgid "%s\t**** Beginning of log ****"
msgstr "**** Naplófájl kezdete "
diff --git a/po/it.po b/po/it.po
index aa95ce994..4cd783e24 100644
--- a/po/it.po
+++ b/po/it.po
@@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
-"POT-Creation-Date: 2019-10-06 09:20+0200\n"
+"POT-Creation-Date: 2019-10-06 13:24+0200\n"
"PO-Revision-Date: 2019-05-13 21:31+0200\n"
"Last-Translator: Esteban I. Ruiz Moreno <exio4.com@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -10237,6 +10237,10 @@ msgstr "%s%s: impossibile creare la directory per i log (\"%s\")"
msgid "%s%s: unable to write log file \"%s\": %s"
msgstr "%s%s: impossibile scrivere il file di log \"%s\": %s"
+#, fuzzy, c-format
+msgid "%s%s: unable to get file status of log file \"%s\": %s"
+msgstr "%s%s: impossibile scrivere il file di log \"%s\": %s"
+
#, c-format
msgid "%s\t**** Beginning of log ****"
msgstr "%s\t**** Inizio del log ****"
diff --git a/po/ja.po b/po/ja.po
index e0ee6e202..07cd82a8c 100644
--- a/po/ja.po
+++ b/po/ja.po
@@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
-"POT-Creation-Date: 2019-10-06 09:20+0200\n"
+"POT-Creation-Date: 2019-10-06 13:24+0200\n"
"PO-Revision-Date: 2019-09-22 18:54+0200\n"
"Last-Translator: AYANOKOUZI, Ryuunosuke <i38w7i3@yahoo.co.jp>\n"
"Language-Team: Japanese <https://github.com/l/weechat/tree/master/"
@@ -10869,6 +10869,10 @@ msgstr "%s%s: ログ用のディレクトリを作成できません (\"%s\")"
msgid "%s%s: unable to write log file \"%s\": %s"
msgstr "%s%s: ログファイル \"%s\" の書き込みに失敗: %s"
+#, fuzzy, c-format
+msgid "%s%s: unable to get file status of log file \"%s\": %s"
+msgstr "%s%s: ログファイル \"%s\" の書き込みに失敗: %s"
+
#, c-format
msgid "%s\t**** Beginning of log ****"
msgstr "%s\t**** ログの最初 ****"
diff --git a/po/pl.po b/po/pl.po
index 5ae510b6b..8dce6d07b 100644
--- a/po/pl.po
+++ b/po/pl.po
@@ -22,7 +22,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
-"POT-Creation-Date: 2019-10-06 09:20+0200\n"
+"POT-Creation-Date: 2019-10-06 13:24+0200\n"
"PO-Revision-Date: 2019-09-22 18:54+0200\n"
"Last-Translator: Krzysztof Korościk <soltys@soltys.info>\n"
"Language-Team: Polish <kde-i18n-doc@kde.org>\n"
@@ -11035,6 +11035,10 @@ msgstr "%s%s: nie można utworzyć katalogu dla logów (\"%s\")"
msgid "%s%s: unable to write log file \"%s\": %s"
msgstr "%s%s: nie można zapisać pliku z logiem \"%s\": %s"
+#, fuzzy, c-format
+msgid "%s%s: unable to get file status of log file \"%s\": %s"
+msgstr "%s%s: nie można zapisać pliku z logiem \"%s\": %s"
+
#, c-format
msgid "%s\t**** Beginning of log ****"
msgstr "%s\t**** Początek logu ****"
diff --git a/po/pt.po b/po/pt.po
index b45ae64e7..da6569796 100644
--- a/po/pt.po
+++ b/po/pt.po
@@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
-"POT-Creation-Date: 2019-10-06 09:20+0200\n"
+"POT-Creation-Date: 2019-10-06 13:24+0200\n"
"PO-Revision-Date: 2019-09-22 18:54+0200\n"
"Last-Translator: Vasco Almeida <vascomalmeida@sapo.pt>\n"
"Language-Team: Portuguese <>\n"
@@ -10704,6 +10704,10 @@ msgstr "%s%s: não foi possível criar diretório para registos (\"%s\")"
msgid "%s%s: unable to write log file \"%s\": %s"
msgstr "%s%s: não foi possível escrever o ficheiro de registo \"%s\": %s"
+#, fuzzy, c-format
+msgid "%s%s: unable to get file status of log file \"%s\": %s"
+msgstr "%s%s: não foi possível escrever o ficheiro de registo \"%s\": %s"
+
#, c-format
msgid "%s\t**** Beginning of log ****"
msgstr "%s\t**** Início do registo ****"
diff --git a/po/pt_BR.po b/po/pt_BR.po
index 9d92eb611..ef08ae15f 100644
--- a/po/pt_BR.po
+++ b/po/pt_BR.po
@@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
-"POT-Creation-Date: 2019-10-06 09:20+0200\n"
+"POT-Creation-Date: 2019-10-06 13:24+0200\n"
"PO-Revision-Date: 2019-05-13 21:32+0200\n"
"Last-Translator: Eduardo Elias <camponez@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -9570,6 +9570,10 @@ msgstr "%s%s: não foi possível criar diretório para registros (\"%s\")"
msgid "%s%s: unable to write log file \"%s\": %s"
msgstr "%s%s: não foi possível escrever arquivo de registro \"%s\": %s"
+#, fuzzy, c-format
+msgid "%s%s: unable to get file status of log file \"%s\": %s"
+msgstr "%s%s: não foi possível escrever arquivo de registro \"%s\": %s"
+
#, c-format
msgid "%s\t**** Beginning of log ****"
msgstr "%s\t*** Início do registro ****"
diff --git a/po/ru.po b/po/ru.po
index efaa2dd06..3412466b0 100644
--- a/po/ru.po
+++ b/po/ru.po
@@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
-"POT-Creation-Date: 2019-10-06 09:20+0200\n"
+"POT-Creation-Date: 2019-10-06 13:24+0200\n"
"PO-Revision-Date: 2019-05-13 21:32+0200\n"
"Last-Translator: Aleksey V Zapparov AKA ixti <ixti@member.fsf.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -9160,6 +9160,10 @@ msgid "%s%s: unable to write log file \"%s\": %s"
msgstr "Не могу записать лог-файл \"%s\"\n"
#, fuzzy, c-format
+msgid "%s%s: unable to get file status of log file \"%s\": %s"
+msgstr "Не могу записать лог-файл \"%s\"\n"
+
+#, fuzzy, c-format
msgid "%s\t**** Beginning of log ****"
msgstr "**** Начало log-файла"
diff --git a/po/tr.po b/po/tr.po
index 4e35404e9..78269a508 100644
--- a/po/tr.po
+++ b/po/tr.po
@@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
-"POT-Creation-Date: 2019-10-06 09:20+0200\n"
+"POT-Creation-Date: 2019-10-06 13:24+0200\n"
"PO-Revision-Date: 2019-05-13 21:32+0200\n"
"Last-Translator: Hasan Kiran <sunder67@hotmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -8329,6 +8329,10 @@ msgstr ""
msgid "%s%s: unable to write log file \"%s\": %s"
msgstr "%sHata: dosya \"%s\" oluşturulamaz"
+#, fuzzy, c-format
+msgid "%s%s: unable to get file status of log file \"%s\": %s"
+msgstr "%sHata: dosya \"%s\" oluşturulamaz"
+
#, c-format
msgid "%s\t**** Beginning of log ****"
msgstr ""
diff --git a/po/weechat.pot b/po/weechat.pot
index 2dacbbae0..920b98bea 100644
--- a/po/weechat.pot
+++ b/po/weechat.pot
@@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
-"POT-Creation-Date: 2019-10-06 09:20+0200\n"
+"POT-Creation-Date: 2019-10-06 13:24+0200\n"
"PO-Revision-Date: 2014-08-16 10:27+0200\n"
"Last-Translator: Sébastien Helleu <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -8193,6 +8193,10 @@ msgid "%s%s: unable to write log file \"%s\": %s"
msgstr ""
#, c-format
+msgid "%s%s: unable to get file status of log file \"%s\": %s"
+msgstr ""
+
+#, c-format
msgid "%s\t**** Beginning of log ****"
msgstr ""
diff --git a/src/plugins/logger/logger-buffer.c b/src/plugins/logger/logger-buffer.c
index b5a2f7e49..129fe1b23 100644
--- a/src/plugins/logger/logger-buffer.c
+++ b/src/plugins/logger/logger-buffer.c
@@ -91,6 +91,7 @@ logger_buffer_add (struct t_gui_buffer *buffer, int log_level)
new_logger_buffer->buffer = buffer;
new_logger_buffer->log_filename = NULL;
new_logger_buffer->log_file = NULL;
+ new_logger_buffer->log_file_inode = 0;
new_logger_buffer->log_enabled = 1;
new_logger_buffer->log_level = log_level;
new_logger_buffer->write_start_info_line = 1;
@@ -234,6 +235,8 @@ logger_buffer_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!weechat_infolist_new_var_pointer (ptr_item, "log_file", logger_buffer->log_file))
return 0;
+ if (!weechat_infolist_new_var_buffer (ptr_item, "log_file_inode", &(logger_buffer->log_file_inode), sizeof(logger_buffer->log_file_inode)))
+ return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "log_enabled", logger_buffer->log_enabled))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "log_level", logger_buffer->log_level))
diff --git a/src/plugins/logger/logger-buffer.h b/src/plugins/logger/logger-buffer.h
index 8163bdfa7..c706a9098 100644
--- a/src/plugins/logger/logger-buffer.h
+++ b/src/plugins/logger/logger-buffer.h
@@ -21,6 +21,9 @@
#define WEECHAT_PLUGIN_LOGGER_BUFFER_H
#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
struct t_infolist;
@@ -29,6 +32,7 @@ struct t_logger_buffer
struct t_gui_buffer *buffer; /* pointer to buffer */
char *log_filename; /* log filename */
FILE *log_file; /* log file */
+ ino_t log_file_inode; /* inode of log file */
int log_enabled; /* log enabled ? */
int log_level; /* log level (0..9) */
int write_start_info_line; /* 1 if start info line must be */
diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c
index a41d44dfe..3532b9716 100644
--- a/src/plugins/logger/logger.c
+++ b/src/plugins/logger/logger.c
@@ -516,87 +516,143 @@ logger_set_log_filename (struct t_logger_buffer *logger_buffer)
}
/*
- * Writes a line to log file.
+ * Creates a log file.
+ *
+ * Returns:
+ * 1: OK
+ * 0: error
*/
-void
-logger_write_line (struct t_logger_buffer *logger_buffer,
- const char *format, ...)
+int
+logger_create_log_file (struct t_logger_buffer *logger_buffer)
{
- char *message, buf_time[256], buf_beginning[1024], *charset;
+ char *charset, *message, buf_time[256], buf_beginning[1024];
+ int log_level, rc;
time_t seconds;
struct tm *date_tmp;
- int log_level;
+ struct stat statbuf;
- if (!logger_buffer->log_file)
+ if (logger_buffer->log_file)
{
- log_level = logger_get_level_for_buffer (logger_buffer->buffer);
- if (log_level == 0)
- {
- logger_buffer_free (logger_buffer);
- return;
- }
- if (!logger_create_directory ())
- {
- weechat_printf_date_tags (
- NULL, 0, "no_log",
- _("%s%s: unable to create directory for logs "
- "(\"%s\")"),
- weechat_prefix ("error"), LOGGER_PLUGIN_NAME,
- weechat_config_string (logger_config_file_path));
- logger_buffer_free (logger_buffer);
- return;
- }
- if (!logger_buffer->log_filename)
- logger_set_log_filename (logger_buffer);
- if (!logger_buffer->log_filename)
+ /*
+ * check that the inode has not changed, otherwise that means the file
+ * was deleted, and we must reopen it
+ */
+ rc = stat (logger_buffer->log_filename, &statbuf);
+ if ((rc == 0) && (statbuf.st_ino == logger_buffer->log_file_inode))
{
- logger_buffer_free (logger_buffer);
- return;
+ /* inode has not changed, we can write in this file */
+ return 1;
}
+ fclose (logger_buffer->log_file);
+ logger_buffer->log_file = NULL;
+ logger_buffer->log_file_inode = 0;
+ }
- logger_buffer->log_file =
- fopen (logger_buffer->log_filename, "a");
- if (!logger_buffer->log_file)
- {
- weechat_printf_date_tags (
- NULL, 0, "no_log",
- _("%s%s: unable to write log file \"%s\": %s"),
- weechat_prefix ("error"), LOGGER_PLUGIN_NAME,
- logger_buffer->log_filename, strerror (errno));
- logger_buffer_free (logger_buffer);
- return;
- }
+ /* get log level */
+ log_level = logger_get_level_for_buffer (logger_buffer->buffer);
+ if (log_level == 0)
+ {
+ logger_buffer_free (logger_buffer);
+ return 0;
+ }
- if (weechat_config_boolean (logger_config_file_info_lines)
- && logger_buffer->write_start_info_line)
+ /* create directory */
+ if (!logger_create_directory ())
+ {
+ weechat_printf_date_tags (
+ NULL, 0, "no_log",
+ _("%s%s: unable to create directory for logs "
+ "(\"%s\")"),
+ weechat_prefix ("error"), LOGGER_PLUGIN_NAME,
+ weechat_config_string (logger_config_file_path));
+ logger_buffer_free (logger_buffer);
+ return 0;
+ }
+ if (!logger_buffer->log_filename)
+ logger_set_log_filename (logger_buffer);
+ if (!logger_buffer->log_filename)
+ {
+ logger_buffer_free (logger_buffer);
+ return 0;
+ }
+
+ /* create or append to log file */
+ logger_buffer->log_file =
+ fopen (logger_buffer->log_filename, "a");
+ if (!logger_buffer->log_file)
+ {
+ weechat_printf_date_tags (
+ NULL, 0, "no_log",
+ _("%s%s: unable to write log file \"%s\": %s"),
+ weechat_prefix ("error"), LOGGER_PLUGIN_NAME,
+ logger_buffer->log_filename, strerror (errno));
+ logger_buffer_free (logger_buffer);
+ return 0;
+ }
+
+ /* get file inode */
+ rc = stat (logger_buffer->log_filename, &statbuf);
+ if (rc != 0)
+ {
+ weechat_printf_date_tags (
+ NULL, 0, "no_log",
+ _("%s%s: unable to get file status of log file \"%s\": %s"),
+ weechat_prefix ("error"), LOGGER_PLUGIN_NAME,
+ logger_buffer->log_filename, strerror (errno));
+ fclose (logger_buffer->log_file);
+ logger_buffer->log_file = NULL;
+ logger_buffer->log_file_inode = 0;
+ logger_buffer_free (logger_buffer);
+ return 0;
+ }
+ logger_buffer->log_file_inode = statbuf.st_ino;
+
+ /* write info line */
+ if (weechat_config_boolean (logger_config_file_info_lines)
+ && logger_buffer->write_start_info_line)
+ {
+ buf_time[0] = '\0';
+ seconds = time (NULL);
+ date_tmp = localtime (&seconds);
+ if (date_tmp)
{
- buf_time[0] = '\0';
- seconds = time (NULL);
- date_tmp = localtime (&seconds);
- if (date_tmp)
- {
- if (strftime (buf_time, sizeof (buf_time) - 1,
- weechat_config_string (logger_config_file_time_format),
- date_tmp) == 0)
- buf_time[0] = '\0';
- }
- snprintf (buf_beginning, sizeof (buf_beginning),
- _("%s\t**** Beginning of log ****"),
- buf_time);
- charset = weechat_info_get ("charset_terminal", "");
- message = (charset) ?
- weechat_iconv_from_internal (charset, buf_beginning) : NULL;
- fprintf (logger_buffer->log_file,
- "%s\n", (message) ? message : buf_beginning);
- if (charset)
- free (charset);
- if (message)
- free (message);
- logger_buffer->flush_needed = 1;
+ if (strftime (buf_time, sizeof (buf_time) - 1,
+ weechat_config_string (logger_config_file_time_format),
+ date_tmp) == 0)
+ buf_time[0] = '\0';
}
- logger_buffer->write_start_info_line = 0;
+ snprintf (buf_beginning, sizeof (buf_beginning),
+ _("%s\t**** Beginning of log ****"),
+ buf_time);
+ charset = weechat_info_get ("charset_terminal", "");
+ message = (charset) ?
+ weechat_iconv_from_internal (charset, buf_beginning) : NULL;
+ fprintf (logger_buffer->log_file,
+ "%s\n", (message) ? message : buf_beginning);
+ if (charset)
+ free (charset);
+ if (message)
+ free (message);
+ logger_buffer->flush_needed = 1;
}
+ logger_buffer->write_start_info_line = 0;
+
+ return 1;
+}
+
+/*
+ * Writes a line to log file.
+ */
+
+void
+logger_write_line (struct t_logger_buffer *logger_buffer,
+ const char *format, ...)
+{
+ char *charset, *message;
+
+ if (!logger_create_log_file (logger_buffer))
+ return;
weechat_va_format (format);
if (vbuffer)
@@ -656,6 +712,7 @@ logger_stop (struct t_logger_buffer *logger_buffer, int write_info_line)
}
fclose (logger_buffer->log_file);
logger_buffer->log_file = NULL;
+ logger_buffer->log_file_inode = 0;
}
logger_buffer_free (logger_buffer);
}
@@ -716,6 +773,7 @@ logger_start_buffer (struct t_gui_buffer *buffer, int write_info_line)
{
fclose (ptr_logger_buffer->log_file);
ptr_logger_buffer->log_file = NULL;
+ ptr_logger_buffer->log_file_inode = 0;
}
}
}