Moved content of src/common/log.c to src/gui/gui-log.c, log.c is now used for WeeChat log file
This commit is contained in:
parent
1bc71392c4
commit
0eea93bba3
@ -40,6 +40,7 @@
|
||||
./src/gui/gui-buffer.c
|
||||
./src/gui/gui-common.c
|
||||
./src/gui/gui-keyboard.c
|
||||
./src/gui/gui-log.c
|
||||
./src/gui/gui-panel.c
|
||||
./src/gui/gui-window.c
|
||||
./src/gui/gui.h
|
||||
|
@ -30,11 +30,12 @@
|
||||
|
||||
#include "weechat.h"
|
||||
#include "command.h"
|
||||
#include "fifo.h"
|
||||
#include "log.h"
|
||||
#include "session.h"
|
||||
#include "utf8.h"
|
||||
#include "weelist.h"
|
||||
#include "weeconfig.h"
|
||||
#include "session.h"
|
||||
#include "fifo.h"
|
||||
#include "utf8.h"
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
@ -3872,8 +3873,7 @@ weechat_cmd_upgrade (t_irc_server *server, t_irc_channel *channel,
|
||||
(void) config_write (NULL);
|
||||
gui_main_end ();
|
||||
fifo_remove ();
|
||||
if (weechat_log_file)
|
||||
fclose (weechat_log_file);
|
||||
weechat_log_close ();
|
||||
|
||||
execvp (exec_args[0], exec_args);
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "weechat.h"
|
||||
#include "fifo.h"
|
||||
#include "command.h"
|
||||
#include "log.h"
|
||||
#include "weeconfig.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
|
217
src/common/log.c
217
src/common/log.c
@ -17,7 +17,7 @@
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* log.c: log buffers to files */
|
||||
/* log.c: WeeChat log file */
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
@ -25,164 +25,115 @@
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/file.h>
|
||||
|
||||
#include "weechat.h"
|
||||
#include "log.h"
|
||||
#include "weeconfig.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
|
||||
FILE *weechat_log_file = NULL; /* WeeChat log file (~/.weechat/weechat.log) */
|
||||
|
||||
|
||||
/*
|
||||
* log_write_date: writes date to log file
|
||||
* weechat_log_init: initialize log file
|
||||
*/
|
||||
|
||||
void
|
||||
log_write_date (t_gui_buffer *buffer)
|
||||
weechat_log_init ()
|
||||
{
|
||||
static char buf_time[256];
|
||||
int filename_length;
|
||||
char *filename;
|
||||
|
||||
filename_length = strlen (weechat_home) + 64;
|
||||
filename =
|
||||
(char *) malloc (filename_length * sizeof (char));
|
||||
snprintf (filename, filename_length, "%s/%s", weechat_home, WEECHAT_LOG_NAME);
|
||||
|
||||
weechat_log_file = fopen (filename, "wt");
|
||||
if (!weechat_log_file
|
||||
|| (flock (fileno (weechat_log_file), LOCK_EX | LOCK_NB) != 0))
|
||||
{
|
||||
fprintf (stderr,
|
||||
_("%s unable to create/append to log file (%s/%s)\n"
|
||||
"If another WeeChat process is using this file, try to run WeeChat\n"
|
||||
"with another home using \"--dir\" command line option.\n"),
|
||||
WEECHAT_ERROR, weechat_home, WEECHAT_LOG_NAME);
|
||||
exit (1);
|
||||
}
|
||||
free (filename);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_log_printf: write a message in WeeChat log (<weechat_home>/weechat.log)
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_log_printf (char *message, ...)
|
||||
{
|
||||
static char buffer[4096];
|
||||
char *ptr_buffer;
|
||||
va_list argptr;
|
||||
static time_t seconds;
|
||||
struct tm *date_tmp;
|
||||
|
||||
if (buffer->log_file)
|
||||
{
|
||||
seconds = time (NULL);
|
||||
date_tmp = localtime (&seconds);
|
||||
if (date_tmp)
|
||||
{
|
||||
strftime (buf_time, sizeof (buf_time) - 1, cfg_log_timestamp, date_tmp);
|
||||
fprintf (buffer->log_file, "%s ", buf_time);
|
||||
fflush (buffer->log_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* log_write_line: writes a line to log file
|
||||
*/
|
||||
|
||||
void
|
||||
log_write_line (t_gui_buffer *buffer, char *message)
|
||||
{
|
||||
char *msg_no_color;
|
||||
|
||||
if (buffer->log_file)
|
||||
{
|
||||
msg_no_color = (char *)gui_color_decode ((unsigned char *)message, 0);
|
||||
fprintf (buffer->log_file, "%s\n",
|
||||
(msg_no_color) ? msg_no_color : message);
|
||||
fflush (buffer->log_file);
|
||||
if (msg_no_color)
|
||||
free (msg_no_color);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* log_write: writes a message to log file
|
||||
*/
|
||||
|
||||
void
|
||||
log_write (t_gui_buffer *buffer, char *message)
|
||||
{
|
||||
char *msg_no_color;
|
||||
|
||||
if (buffer->log_file)
|
||||
{
|
||||
msg_no_color = (char *)gui_color_decode ((unsigned char *)message, 0);
|
||||
fprintf (buffer->log_file, "%s",
|
||||
(msg_no_color) ? msg_no_color : message);
|
||||
fflush (buffer->log_file);
|
||||
if (msg_no_color)
|
||||
free (msg_no_color);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* log_start: starts a log
|
||||
*/
|
||||
|
||||
void
|
||||
log_start (t_gui_buffer *buffer)
|
||||
{
|
||||
int length;
|
||||
char *log_path, *log_path2;
|
||||
|
||||
log_path = weechat_strreplace (cfg_log_path, "~", getenv ("HOME"));
|
||||
log_path2 = weechat_strreplace (log_path, "%h", weechat_home);
|
||||
if (!log_path || !log_path2)
|
||||
{
|
||||
weechat_log_printf (_("Not enough memory to write log file for a buffer\n"));
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
free (log_path2);
|
||||
if (!weechat_log_file)
|
||||
return;
|
||||
}
|
||||
length = strlen (log_path2) + 64;
|
||||
if (SERVER(buffer))
|
||||
length += strlen (SERVER(buffer)->name);
|
||||
if (CHANNEL(buffer))
|
||||
length += strlen (CHANNEL(buffer)->name);
|
||||
|
||||
buffer->log_filename = (char *) malloc (length);
|
||||
if (!buffer->log_filename)
|
||||
va_start (argptr, message);
|
||||
vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
/* keep only valid chars */
|
||||
ptr_buffer = buffer;
|
||||
while (ptr_buffer[0])
|
||||
{
|
||||
weechat_log_printf (_("Not enough memory to write log file for a buffer\n"));
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
free (log_path2);
|
||||
return;
|
||||
if ((ptr_buffer[0] != '\n')
|
||||
&& (ptr_buffer[0] != '\r')
|
||||
&& ((unsigned char)(ptr_buffer[0]) < 32))
|
||||
ptr_buffer[0] = '.';
|
||||
ptr_buffer++;
|
||||
}
|
||||
|
||||
strcpy (buffer->log_filename, log_path2);
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
free (log_path2);
|
||||
if (buffer->log_filename[strlen (buffer->log_filename) - 1] != DIR_SEPARATOR_CHAR)
|
||||
strcat (buffer->log_filename, DIR_SEPARATOR);
|
||||
|
||||
if (SERVER(buffer))
|
||||
{
|
||||
strcat (buffer->log_filename, SERVER(buffer)->name);
|
||||
strcat (buffer->log_filename, ".");
|
||||
}
|
||||
if (CHANNEL(buffer))
|
||||
{
|
||||
strcat (buffer->log_filename, CHANNEL(buffer)->name);
|
||||
strcat (buffer->log_filename, ".");
|
||||
}
|
||||
strcat (buffer->log_filename, "weechatlog");
|
||||
|
||||
buffer->log_file = fopen (buffer->log_filename, "a");
|
||||
if (!buffer->log_file)
|
||||
{
|
||||
weechat_log_printf (_("Unable to write log file for a buffer\n"));
|
||||
free (buffer->log_filename);
|
||||
return;
|
||||
}
|
||||
log_write (buffer, _("**** Beginning of log "));
|
||||
log_write_date (buffer);
|
||||
log_write (buffer, "****\n");
|
||||
seconds = time (NULL);
|
||||
date_tmp = localtime (&seconds);
|
||||
if (date_tmp)
|
||||
fprintf (weechat_log_file, "[%04d-%02d-%02d %02d:%02d:%02d] %s",
|
||||
date_tmp->tm_year + 1900, date_tmp->tm_mon + 1, date_tmp->tm_mday,
|
||||
date_tmp->tm_hour, date_tmp->tm_min, date_tmp->tm_sec,
|
||||
buffer);
|
||||
else
|
||||
fprintf (weechat_log_file, "%s", buffer);
|
||||
fflush (weechat_log_file);
|
||||
}
|
||||
|
||||
/*
|
||||
* log_end: ends a log
|
||||
* weechat_log_close: close log file
|
||||
*/
|
||||
|
||||
void
|
||||
log_end (t_gui_buffer *buffer)
|
||||
weechat_log_close ()
|
||||
{
|
||||
if (buffer->log_file)
|
||||
if (weechat_log_file)
|
||||
{
|
||||
flock (fileno (weechat_log_file), LOCK_UN);
|
||||
fclose (weechat_log_file);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_log_crash_rename: rename log file when crashing
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_log_crash_rename ()
|
||||
{
|
||||
char *oldname, *newname;
|
||||
|
||||
oldname = (char *) malloc (strlen (weechat_home) + 64);
|
||||
newname = (char *) malloc (strlen (weechat_home) + 64);
|
||||
if (oldname && newname)
|
||||
{
|
||||
log_write (buffer, _("**** End of log "));
|
||||
log_write_date (buffer);
|
||||
log_write (buffer, "****\n");
|
||||
fclose (buffer->log_file);
|
||||
buffer->log_file = NULL;
|
||||
}
|
||||
if (buffer->log_filename)
|
||||
free (buffer->log_filename);
|
||||
}
|
||||
|
@ -21,13 +21,11 @@
|
||||
#ifndef __WEECHAT_LOG_H
|
||||
#define __WEECHAT_LOG_H 1
|
||||
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
extern FILE *weechat_log_file;
|
||||
|
||||
extern void log_write_date (t_gui_buffer *);
|
||||
extern void log_write_line (t_gui_buffer *, char *);
|
||||
extern void log_write (t_gui_buffer *, char *);
|
||||
extern void log_start (t_gui_buffer *);
|
||||
extern void log_end (t_gui_buffer *);
|
||||
extern void weechat_log_init ();
|
||||
extern void weechat_log_close ();
|
||||
extern void weechat_log_printf (char *, ...);
|
||||
extern void weechat_log_crash_rename ();
|
||||
|
||||
#endif /* log.h */
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include "weechat.h"
|
||||
#include "session.h"
|
||||
#include "log.h"
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
|
@ -42,9 +42,7 @@
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
@ -63,11 +61,12 @@
|
||||
|
||||
#include "weechat.h"
|
||||
#include "backtrace.h"
|
||||
#include "weeconfig.h"
|
||||
#include "command.h"
|
||||
#include "fifo.h"
|
||||
#include "utf8.h"
|
||||
#include "log.h"
|
||||
#include "session.h"
|
||||
#include "utf8.h"
|
||||
#include "weeconfig.h"
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
@ -76,19 +75,18 @@
|
||||
#endif
|
||||
|
||||
|
||||
char *weechat_argv0 = NULL; /* WeeChat binary file name (argv[0]) */
|
||||
char *weechat_session = NULL; /* WeeChat session file (for /upgrade command) */
|
||||
time_t weechat_start_time; /* WeeChat start time (used by /uptime command) */
|
||||
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
|
||||
int sigsegv = 0; /* SIGSEGV received? */
|
||||
char *weechat_home = NULL; /* WeeChat home dir. (example: /home/toto/.weechat) */
|
||||
FILE *weechat_log_file = NULL; /* WeeChat log file (~/.weechat/weechat.log) */
|
||||
char *weechat_argv0 = NULL; /* WeeChat binary file name (argv[0]) */
|
||||
char *weechat_session = NULL; /* WeeChat session file (for /upgrade cmd) */
|
||||
time_t weechat_start_time; /* WeeChat start time (used by /uptime cmd) */
|
||||
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
|
||||
int sigsegv = 0; /* SIGSEGV received? */
|
||||
char *weechat_home = NULL; /* WeeChat home dir. (default: ~/.weechat) */
|
||||
|
||||
char *local_charset = NULL; /* local charset, for example: ISO-8859-1, UTF-8 */
|
||||
char *local_charset = NULL; /* local charset, for ex.: ISO-8859-1, UTF-8 */
|
||||
|
||||
int server_cmd_line; /* at least one server on WeeChat command line */
|
||||
int auto_connect; /* enabled by default, can by disabled on cmd line */
|
||||
int auto_load_plugins; /* enabled by default, can by disabled on cmd line */
|
||||
int server_cmd_line; /* at least 1 server on WeeChat command line */
|
||||
int auto_connect; /* enabled by default (cmd option to disable) */
|
||||
int auto_load_plugins; /* enabled by default (cmd option to disable) */
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */
|
||||
@ -197,49 +195,6 @@ ascii_strncasecmp (char *string1, char *string2, int max)
|
||||
return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_log_printf: displays a message in WeeChat log (<weechat_home>/weechat.log)
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_log_printf (char *message, ...)
|
||||
{
|
||||
static char buffer[4096];
|
||||
char *ptr_buffer;
|
||||
va_list argptr;
|
||||
static time_t seconds;
|
||||
struct tm *date_tmp;
|
||||
|
||||
if (!weechat_log_file)
|
||||
return;
|
||||
|
||||
va_start (argptr, message);
|
||||
vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
/* keep only valid chars */
|
||||
ptr_buffer = buffer;
|
||||
while (ptr_buffer[0])
|
||||
{
|
||||
if ((ptr_buffer[0] != '\n')
|
||||
&& (ptr_buffer[0] != '\r')
|
||||
&& ((unsigned char)(ptr_buffer[0]) < 32))
|
||||
ptr_buffer[0] = '.';
|
||||
ptr_buffer++;
|
||||
}
|
||||
|
||||
seconds = time (NULL);
|
||||
date_tmp = localtime (&seconds);
|
||||
if (date_tmp)
|
||||
fprintf (weechat_log_file, "[%04d-%02d-%02d %02d:%02d:%02d] %s",
|
||||
date_tmp->tm_year + 1900, date_tmp->tm_mon + 1, date_tmp->tm_mday,
|
||||
date_tmp->tm_hour, date_tmp->tm_min, date_tmp->tm_sec,
|
||||
buffer);
|
||||
else
|
||||
fprintf (weechat_log_file, "%s", buffer);
|
||||
fflush (weechat_log_file);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_iconv: convert string to another charset
|
||||
*/
|
||||
@ -834,35 +789,6 @@ weechat_init_vars ()
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_init_log: initialize log file
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_init_log ()
|
||||
{
|
||||
int filename_length;
|
||||
char *filename;
|
||||
|
||||
filename_length = strlen (weechat_home) + 64;
|
||||
filename =
|
||||
(char *) malloc (filename_length * sizeof (char));
|
||||
snprintf (filename, filename_length, "%s/" WEECHAT_LOG_NAME, weechat_home);
|
||||
|
||||
weechat_log_file = fopen (filename, "wt");
|
||||
if (!weechat_log_file
|
||||
|| (flock (fileno (weechat_log_file), LOCK_EX | LOCK_NB) != 0))
|
||||
{
|
||||
fprintf (stderr,
|
||||
_("%s unable to create/append to log file (%s/%s)\n"
|
||||
"If another WeeChat process is using this file, try to run WeeChat\n"
|
||||
"with another home using \"--dir\" command line option.\n"),
|
||||
WEECHAT_ERROR, weechat_home, WEECHAT_LOG_NAME);
|
||||
exit (1);
|
||||
}
|
||||
free (filename);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_config_read: read WeeChat config file
|
||||
*/
|
||||
@ -948,11 +874,7 @@ weechat_shutdown (int return_code, int crash)
|
||||
fifo_remove ();
|
||||
if (weechat_home)
|
||||
free (weechat_home);
|
||||
if (weechat_log_file)
|
||||
{
|
||||
flock (fileno (weechat_log_file), LOCK_UN);
|
||||
fclose (weechat_log_file);
|
||||
}
|
||||
weechat_log_close ();
|
||||
if (local_charset)
|
||||
free (local_charset);
|
||||
alias_free_all ();
|
||||
@ -1085,9 +1007,10 @@ weechat_sigsegv ()
|
||||
weechat_home);
|
||||
fprintf (stderr, "***\n");
|
||||
fprintf (stderr, "*** Please help WeeChat developers to fix this bug:\n");
|
||||
fprintf (stderr, "*** 1. if you have a core file, please run: gdb weechat-curses core\n");
|
||||
fprintf (stderr, "*** 1. If you have a core file, please run: gdb weechat-curses core\n");
|
||||
fprintf (stderr, "*** then issue \"bt\" command and send result to developers\n");
|
||||
fprintf (stderr, "*** 2. otherwise send backtrace displayed below and weechat.log\n");
|
||||
fprintf (stderr, "*** To enable core files with bash shell: ulimit -c 10000\n");
|
||||
fprintf (stderr, "*** 2. Otherwise send backtrace displayed below and weechat.log\n");
|
||||
fprintf (stderr, "*** (be careful, private info may be in this file since\n");
|
||||
fprintf (stderr, "*** part of chats are displayed, so remove lines if needed)\n\n");
|
||||
|
||||
@ -1125,7 +1048,7 @@ main (int argc, char *argv[])
|
||||
gui_keyboard_init (); /* init keyb. (default key bindings)*/
|
||||
weechat_parse_args (argc, argv); /* parse command line args */
|
||||
weechat_create_home_dirs (); /* create WeeChat directories */
|
||||
weechat_init_log (); /* init log file */
|
||||
weechat_log_init (); /* init log file */
|
||||
command_index_build (); /* build cmd index for completion */
|
||||
weechat_config_read (); /* read configuration */
|
||||
weechat_create_config_dirs (); /* create config directories */
|
||||
|
@ -98,7 +98,6 @@ extern char *weechat_argv0;
|
||||
extern time_t weechat_start_time;
|
||||
extern int quit_weechat;
|
||||
extern char *weechat_home;
|
||||
extern FILE *weechat_log_file;
|
||||
extern char *local_charset;
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
@ -109,7 +108,6 @@ extern void ascii_tolower (char *);
|
||||
extern void ascii_toupper (char *);
|
||||
extern int ascii_strcasecmp (char *, char *);
|
||||
extern int ascii_strncasecmp (char *, char *, int);
|
||||
extern void weechat_log_printf (char *, ...);
|
||||
extern char *weechat_iconv (char *, char *, char *);
|
||||
extern char *weechat_strreplace (char *, char *, char *);
|
||||
extern void weechat_dump (int);
|
||||
|
@ -1282,23 +1282,23 @@ config_change_log ()
|
||||
if (BUFFER_IS_SERVER(ptr_buffer))
|
||||
{
|
||||
if (cfg_log_auto_server && !ptr_buffer->log_file)
|
||||
log_start (ptr_buffer);
|
||||
gui_log_start (ptr_buffer);
|
||||
else if (!cfg_log_auto_server && ptr_buffer->log_file)
|
||||
log_end (ptr_buffer);
|
||||
gui_log_end (ptr_buffer);
|
||||
}
|
||||
if (BUFFER_IS_CHANNEL(ptr_buffer))
|
||||
{
|
||||
if (cfg_log_auto_channel && !ptr_buffer->log_file)
|
||||
log_start (ptr_buffer);
|
||||
gui_log_start (ptr_buffer);
|
||||
else if (!cfg_log_auto_channel && ptr_buffer->log_file)
|
||||
log_end (ptr_buffer);
|
||||
gui_log_end (ptr_buffer);
|
||||
}
|
||||
if (BUFFER_IS_PRIVATE(ptr_buffer))
|
||||
{
|
||||
if (cfg_log_auto_private && !ptr_buffer->log_file)
|
||||
log_start (ptr_buffer);
|
||||
gui_log_start (ptr_buffer);
|
||||
else if (!cfg_log_auto_private && ptr_buffer->log_file)
|
||||
log_end (ptr_buffer);
|
||||
gui_log_end (ptr_buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ lib_weechat_gui_common_a_SOURCES = gui-buffer.c \
|
||||
gui-common.c \
|
||||
gui-action.c \
|
||||
gui-keyboard.c \
|
||||
gui-log.c \
|
||||
gui-window.c \
|
||||
gui-panel.c \
|
||||
gui.h \
|
||||
|
@ -20,9 +20,7 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\"
|
||||
bin_PROGRAMS = weechat-curses
|
||||
|
||||
if PLUGINS
|
||||
weechat_curses_LDADD = ../gui-common.o ../gui-buffer.o \
|
||||
../gui-window.o ../gui-panel.o \
|
||||
../gui-keyboard.o ../gui-action.o \
|
||||
weechat_curses_LDADD = ../lib_weechat_gui_common.a \
|
||||
../../common/lib_weechat_main.a \
|
||||
../../irc/lib_weechat_irc.a \
|
||||
../../plugins/lib_weechat_plugins.a \
|
||||
@ -30,9 +28,7 @@ weechat_curses_LDADD = ../gui-common.o ../gui-buffer.o \
|
||||
$(NCURSES_LIBS) \
|
||||
$(GNUTLS_LFLAGS)
|
||||
else
|
||||
weechat_curses_LDADD = ../gui-common.o ../gui-buffer.o \
|
||||
../gui-window.o ../gui-panel.o \
|
||||
../gui-keyboard.o ../gui-action.o \
|
||||
weechat_curses_LDADD = ../lib_weechat_gui_common.a \
|
||||
../../common/lib_weechat_main.a \
|
||||
../../irc/lib_weechat_irc.a \
|
||||
$(PLUGINS_LIBS) \
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "../../common/weechat.h"
|
||||
#include "../gui.h"
|
||||
#include "../../common/hotlist.h"
|
||||
#include "../../common/log.h"
|
||||
#include "../../common/weeconfig.h"
|
||||
#include "gui-curses.h"
|
||||
|
||||
|
@ -20,9 +20,7 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(GTK_CFLAGS)
|
||||
bin_PROGRAMS = weechat-gtk
|
||||
|
||||
if PLUGINS
|
||||
weechat_gtk_LDADD = ../gui-common.o ../gui-buffer.o \
|
||||
../gui-window.o ../gui-panel.o \
|
||||
../gui-keyboard.o ../gui-action.o \
|
||||
weechat_gtk_LDADD = ../lib_weechat_gui_common.a \
|
||||
../../common/lib_weechat_main.a \
|
||||
../../irc/lib_weechat_irc.a \
|
||||
../../plugins/lib_weechat_plugins.a \
|
||||
@ -30,9 +28,7 @@ weechat_gtk_LDADD = ../gui-common.o ../gui-buffer.o \
|
||||
$(GTK_LIBS) \
|
||||
$(GNUTLS_LFLAGS)
|
||||
else
|
||||
weechat_gtk_LDADD = ../gui-common.o ../gui-buffer.o \
|
||||
../gui-window.o ../gui-panel.o \
|
||||
../gui-keyboard.o ../gui-action.o \
|
||||
weechat_gtk_LDADD = ../lib_weechat_gui_common.a \
|
||||
../../common/lib_weechat_main.a \
|
||||
../../irc/lib_weechat_irc.a \
|
||||
$(PLUGINS_LIBS) \
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "../../common/weechat.h"
|
||||
#include "../gui.h"
|
||||
#include "../../common/hotlist.h"
|
||||
#include "../../common/log.h"
|
||||
#include "../../common/weeconfig.h"
|
||||
#include "gui-gtk.h"
|
||||
|
||||
|
@ -98,7 +98,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int type,
|
||||
if (cfg_look_one_server_buffer && server && !channel)
|
||||
gui_buffers->all_servers = 1;
|
||||
if (cfg_log_auto_server)
|
||||
log_start (gui_buffers);
|
||||
gui_log_start (gui_buffers);
|
||||
return gui_buffers;
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int type,
|
||||
if ((cfg_log_auto_server && BUFFER_IS_SERVER(new_buffer))
|
||||
|| (cfg_log_auto_channel && BUFFER_IS_CHANNEL(new_buffer))
|
||||
|| (cfg_log_auto_private && BUFFER_IS_PRIVATE(new_buffer)))
|
||||
log_start (new_buffer);
|
||||
gui_log_start (new_buffer);
|
||||
|
||||
/* init input buffer */
|
||||
new_buffer->has_input = (new_buffer->type == BUFFER_TYPE_STANDARD) ? 1 : 0;
|
||||
@ -479,7 +479,7 @@ gui_buffer_free (t_gui_buffer *buffer, int switch_to_another)
|
||||
|
||||
/* close log if opened */
|
||||
if (buffer->log_file)
|
||||
log_end (buffer);
|
||||
gui_log_end (buffer);
|
||||
|
||||
if (buffer->input_buffer)
|
||||
free (buffer->input_buffer);
|
||||
|
@ -193,18 +193,18 @@ gui_add_to_line (t_gui_buffer *buffer, int type, char *nick, char *message)
|
||||
}
|
||||
if (buffer->line_complete && buffer->log_file && buffer->last_line->log_write)
|
||||
{
|
||||
log_write_date (buffer);
|
||||
gui_log_write_date (buffer);
|
||||
if (buffer->last_line->nick)
|
||||
{
|
||||
log_write (buffer, "<");
|
||||
log_write (buffer, buffer->last_line->nick);
|
||||
log_write (buffer, "> ");
|
||||
gui_log_write (buffer, "<");
|
||||
gui_log_write (buffer, buffer->last_line->nick);
|
||||
gui_log_write (buffer, "> ");
|
||||
}
|
||||
if (buffer->last_line->ofs_start_message >= 0)
|
||||
log_write_line (buffer,
|
||||
buffer->last_line->data + buffer->last_line->ofs_start_message);
|
||||
gui_log_write_line (buffer,
|
||||
buffer->last_line->data + buffer->last_line->ofs_start_message);
|
||||
else
|
||||
log_write_line (buffer, buffer->last_line->data);
|
||||
gui_log_write_line (buffer, buffer->last_line->data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "../common/weechat.h"
|
||||
#include "gui.h"
|
||||
#include "../common/command.h"
|
||||
#include "../common/log.h"
|
||||
|
||||
#ifdef PLUGINS
|
||||
#include "../plugins/plugins.h"
|
||||
|
188
src/gui/gui-log.c
Normal file
188
src/gui/gui-log.c
Normal file
@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2006 by FlashCode <flashcode@flashtux.org>
|
||||
* See README for License detail, AUTHORS for developers list.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* gui-log.c: log buffers to files */
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "gui.h"
|
||||
#include "../common/log.h"
|
||||
#include "../common/weeconfig.h"
|
||||
|
||||
|
||||
/*
|
||||
* gui_log_write_date: writes date to log file
|
||||
*/
|
||||
|
||||
void
|
||||
gui_log_write_date (t_gui_buffer *buffer)
|
||||
{
|
||||
static char buf_time[256];
|
||||
static time_t seconds;
|
||||
struct tm *date_tmp;
|
||||
|
||||
if (buffer->log_file)
|
||||
{
|
||||
seconds = time (NULL);
|
||||
date_tmp = localtime (&seconds);
|
||||
if (date_tmp)
|
||||
{
|
||||
strftime (buf_time, sizeof (buf_time) - 1, cfg_log_timestamp, date_tmp);
|
||||
fprintf (buffer->log_file, "%s ", buf_time);
|
||||
fflush (buffer->log_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_log_write_line: writes a line to log file
|
||||
*/
|
||||
|
||||
void
|
||||
gui_log_write_line (t_gui_buffer *buffer, char *message)
|
||||
{
|
||||
char *msg_no_color;
|
||||
|
||||
if (buffer->log_file)
|
||||
{
|
||||
msg_no_color = (char *)gui_color_decode ((unsigned char *)message, 0);
|
||||
fprintf (buffer->log_file, "%s\n",
|
||||
(msg_no_color) ? msg_no_color : message);
|
||||
fflush (buffer->log_file);
|
||||
if (msg_no_color)
|
||||
free (msg_no_color);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_log_write: writes a message to log file
|
||||
*/
|
||||
|
||||
void
|
||||
gui_log_write (t_gui_buffer *buffer, char *message)
|
||||
{
|
||||
char *msg_no_color;
|
||||
|
||||
if (buffer->log_file)
|
||||
{
|
||||
msg_no_color = (char *)gui_color_decode ((unsigned char *)message, 0);
|
||||
fprintf (buffer->log_file, "%s",
|
||||
(msg_no_color) ? msg_no_color : message);
|
||||
fflush (buffer->log_file);
|
||||
if (msg_no_color)
|
||||
free (msg_no_color);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_log_start: starts a log
|
||||
*/
|
||||
|
||||
void
|
||||
gui_log_start (t_gui_buffer *buffer)
|
||||
{
|
||||
int length;
|
||||
char *log_path, *log_path2;
|
||||
|
||||
log_path = weechat_strreplace (cfg_log_path, "~", getenv ("HOME"));
|
||||
log_path2 = weechat_strreplace (log_path, "%h", weechat_home);
|
||||
if (!log_path || !log_path2)
|
||||
{
|
||||
weechat_log_printf (_("Not enough memory to write log file for a buffer\n"));
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
free (log_path2);
|
||||
return;
|
||||
}
|
||||
length = strlen (log_path2) + 64;
|
||||
if (SERVER(buffer))
|
||||
length += strlen (SERVER(buffer)->name);
|
||||
if (CHANNEL(buffer))
|
||||
length += strlen (CHANNEL(buffer)->name);
|
||||
|
||||
buffer->log_filename = (char *) malloc (length);
|
||||
if (!buffer->log_filename)
|
||||
{
|
||||
weechat_log_printf (_("Not enough memory to write log file for a buffer\n"));
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
free (log_path2);
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy (buffer->log_filename, log_path2);
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
free (log_path2);
|
||||
if (buffer->log_filename[strlen (buffer->log_filename) - 1] != DIR_SEPARATOR_CHAR)
|
||||
strcat (buffer->log_filename, DIR_SEPARATOR);
|
||||
|
||||
if (SERVER(buffer))
|
||||
{
|
||||
strcat (buffer->log_filename, SERVER(buffer)->name);
|
||||
strcat (buffer->log_filename, ".");
|
||||
}
|
||||
if (CHANNEL(buffer))
|
||||
{
|
||||
strcat (buffer->log_filename, CHANNEL(buffer)->name);
|
||||
strcat (buffer->log_filename, ".");
|
||||
}
|
||||
strcat (buffer->log_filename, "weechatlog");
|
||||
|
||||
buffer->log_file = fopen (buffer->log_filename, "a");
|
||||
if (!buffer->log_file)
|
||||
{
|
||||
weechat_log_printf (_("Unable to write log file for a buffer\n"));
|
||||
free (buffer->log_filename);
|
||||
return;
|
||||
}
|
||||
gui_log_write (buffer, _("**** Beginning of log "));
|
||||
gui_log_write_date (buffer);
|
||||
gui_log_write (buffer, "****\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_log_end: ends a log
|
||||
*/
|
||||
|
||||
void
|
||||
gui_log_end (t_gui_buffer *buffer)
|
||||
{
|
||||
if (buffer->log_file)
|
||||
{
|
||||
gui_log_write (buffer, _("**** End of log "));
|
||||
gui_log_write_date (buffer);
|
||||
gui_log_write (buffer, "****\n");
|
||||
fclose (buffer->log_file);
|
||||
buffer->log_file = NULL;
|
||||
}
|
||||
if (buffer->log_filename)
|
||||
free (buffer->log_filename);
|
||||
}
|
@ -27,6 +27,7 @@
|
||||
#include "gui-window.h"
|
||||
#include "gui-keyboard.h"
|
||||
|
||||
|
||||
#define gui_printf(buffer, fmt, argz...) \
|
||||
gui_printf_internal(buffer, 1, MSG_TYPE_INFO, NULL, fmt, ##argz)
|
||||
|
||||
@ -42,6 +43,7 @@
|
||||
#define gui_printf_nolog_notime(buffer, fmt, argz...) \
|
||||
gui_printf_internal(buffer, 0, MSG_TYPE_NOLOG, NULL, fmt, ##argz)
|
||||
|
||||
|
||||
typedef struct t_gui_infobar t_gui_infobar;
|
||||
|
||||
struct t_gui_infobar
|
||||
@ -163,6 +165,13 @@ extern int gui_keyboard_pressed (char *);
|
||||
extern void gui_keyboard_free (t_gui_key *);
|
||||
extern void gui_keyboard_free_all ();
|
||||
|
||||
/* log */
|
||||
extern void gui_log_write_date (t_gui_buffer *);
|
||||
extern void gui_log_write_line (t_gui_buffer *, char *);
|
||||
extern void gui_log_write (t_gui_buffer *, char *);
|
||||
extern void gui_log_start (t_gui_buffer *);
|
||||
extern void gui_log_end (t_gui_buffer *);
|
||||
|
||||
/* other */
|
||||
extern void gui_infobar_printf (int, int, char *, ...);
|
||||
extern void gui_infobar_printf_from_buffer (t_gui_buffer *, int, int, char *, char *, ...);
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
#include "../common/log.h"
|
||||
#include "../common/utf8.h"
|
||||
#include "../common/weeconfig.h"
|
||||
#include "../gui/gui.h"
|
||||
|
@ -39,8 +39,9 @@
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
#include "../common/weeconfig.h"
|
||||
#include "../common/log.h"
|
||||
#include "../common/hotlist.h"
|
||||
#include "../common/weeconfig.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
#include "../common/command.h"
|
||||
#include "../common/log.h"
|
||||
|
||||
|
||||
char *ignore_types[] =
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
#include "../common/log.h"
|
||||
#include "../common/weeconfig.h"
|
||||
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
#include "../common/log.h"
|
||||
#include "../common/weeconfig.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
|
@ -258,7 +258,7 @@ weechat_plugin_log (t_weechat_plugin *plugin,
|
||||
va_start (argptr, message);
|
||||
vsnprintf (buf, sizeof (buf) - 1, message, argptr);
|
||||
va_end (argptr);
|
||||
log_write_line (ptr_buffer, buf);
|
||||
gui_log_write_line (ptr_buffer, buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
./src/gui/gui-buffer.c
|
||||
./src/gui/gui-common.c
|
||||
./src/gui/gui-keyboard.c
|
||||
./src/gui/gui-log.c
|
||||
./src/gui/gui-panel.c
|
||||
./src/gui/gui-window.c
|
||||
./src/gui/gui.h
|
||||
|
@ -30,11 +30,12 @@
|
||||
|
||||
#include "weechat.h"
|
||||
#include "command.h"
|
||||
#include "fifo.h"
|
||||
#include "log.h"
|
||||
#include "session.h"
|
||||
#include "utf8.h"
|
||||
#include "weelist.h"
|
||||
#include "weeconfig.h"
|
||||
#include "session.h"
|
||||
#include "fifo.h"
|
||||
#include "utf8.h"
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
@ -3872,8 +3873,7 @@ weechat_cmd_upgrade (t_irc_server *server, t_irc_channel *channel,
|
||||
(void) config_write (NULL);
|
||||
gui_main_end ();
|
||||
fifo_remove ();
|
||||
if (weechat_log_file)
|
||||
fclose (weechat_log_file);
|
||||
weechat_log_close ();
|
||||
|
||||
execvp (exec_args[0], exec_args);
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "weechat.h"
|
||||
#include "fifo.h"
|
||||
#include "command.h"
|
||||
#include "log.h"
|
||||
#include "weeconfig.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* log.c: log buffers to files */
|
||||
/* log.c: WeeChat log file */
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
@ -25,164 +25,115 @@
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/file.h>
|
||||
|
||||
#include "weechat.h"
|
||||
#include "log.h"
|
||||
#include "weeconfig.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
|
||||
FILE *weechat_log_file = NULL; /* WeeChat log file (~/.weechat/weechat.log) */
|
||||
|
||||
|
||||
/*
|
||||
* log_write_date: writes date to log file
|
||||
* weechat_log_init: initialize log file
|
||||
*/
|
||||
|
||||
void
|
||||
log_write_date (t_gui_buffer *buffer)
|
||||
weechat_log_init ()
|
||||
{
|
||||
static char buf_time[256];
|
||||
int filename_length;
|
||||
char *filename;
|
||||
|
||||
filename_length = strlen (weechat_home) + 64;
|
||||
filename =
|
||||
(char *) malloc (filename_length * sizeof (char));
|
||||
snprintf (filename, filename_length, "%s/%s", weechat_home, WEECHAT_LOG_NAME);
|
||||
|
||||
weechat_log_file = fopen (filename, "wt");
|
||||
if (!weechat_log_file
|
||||
|| (flock (fileno (weechat_log_file), LOCK_EX | LOCK_NB) != 0))
|
||||
{
|
||||
fprintf (stderr,
|
||||
_("%s unable to create/append to log file (%s/%s)\n"
|
||||
"If another WeeChat process is using this file, try to run WeeChat\n"
|
||||
"with another home using \"--dir\" command line option.\n"),
|
||||
WEECHAT_ERROR, weechat_home, WEECHAT_LOG_NAME);
|
||||
exit (1);
|
||||
}
|
||||
free (filename);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_log_printf: write a message in WeeChat log (<weechat_home>/weechat.log)
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_log_printf (char *message, ...)
|
||||
{
|
||||
static char buffer[4096];
|
||||
char *ptr_buffer;
|
||||
va_list argptr;
|
||||
static time_t seconds;
|
||||
struct tm *date_tmp;
|
||||
|
||||
if (buffer->log_file)
|
||||
{
|
||||
seconds = time (NULL);
|
||||
date_tmp = localtime (&seconds);
|
||||
if (date_tmp)
|
||||
{
|
||||
strftime (buf_time, sizeof (buf_time) - 1, cfg_log_timestamp, date_tmp);
|
||||
fprintf (buffer->log_file, "%s ", buf_time);
|
||||
fflush (buffer->log_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* log_write_line: writes a line to log file
|
||||
*/
|
||||
|
||||
void
|
||||
log_write_line (t_gui_buffer *buffer, char *message)
|
||||
{
|
||||
char *msg_no_color;
|
||||
|
||||
if (buffer->log_file)
|
||||
{
|
||||
msg_no_color = (char *)gui_color_decode ((unsigned char *)message, 0);
|
||||
fprintf (buffer->log_file, "%s\n",
|
||||
(msg_no_color) ? msg_no_color : message);
|
||||
fflush (buffer->log_file);
|
||||
if (msg_no_color)
|
||||
free (msg_no_color);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* log_write: writes a message to log file
|
||||
*/
|
||||
|
||||
void
|
||||
log_write (t_gui_buffer *buffer, char *message)
|
||||
{
|
||||
char *msg_no_color;
|
||||
|
||||
if (buffer->log_file)
|
||||
{
|
||||
msg_no_color = (char *)gui_color_decode ((unsigned char *)message, 0);
|
||||
fprintf (buffer->log_file, "%s",
|
||||
(msg_no_color) ? msg_no_color : message);
|
||||
fflush (buffer->log_file);
|
||||
if (msg_no_color)
|
||||
free (msg_no_color);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* log_start: starts a log
|
||||
*/
|
||||
|
||||
void
|
||||
log_start (t_gui_buffer *buffer)
|
||||
{
|
||||
int length;
|
||||
char *log_path, *log_path2;
|
||||
|
||||
log_path = weechat_strreplace (cfg_log_path, "~", getenv ("HOME"));
|
||||
log_path2 = weechat_strreplace (log_path, "%h", weechat_home);
|
||||
if (!log_path || !log_path2)
|
||||
{
|
||||
weechat_log_printf (_("Not enough memory to write log file for a buffer\n"));
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
free (log_path2);
|
||||
if (!weechat_log_file)
|
||||
return;
|
||||
}
|
||||
length = strlen (log_path2) + 64;
|
||||
if (SERVER(buffer))
|
||||
length += strlen (SERVER(buffer)->name);
|
||||
if (CHANNEL(buffer))
|
||||
length += strlen (CHANNEL(buffer)->name);
|
||||
|
||||
buffer->log_filename = (char *) malloc (length);
|
||||
if (!buffer->log_filename)
|
||||
va_start (argptr, message);
|
||||
vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
/* keep only valid chars */
|
||||
ptr_buffer = buffer;
|
||||
while (ptr_buffer[0])
|
||||
{
|
||||
weechat_log_printf (_("Not enough memory to write log file for a buffer\n"));
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
free (log_path2);
|
||||
return;
|
||||
if ((ptr_buffer[0] != '\n')
|
||||
&& (ptr_buffer[0] != '\r')
|
||||
&& ((unsigned char)(ptr_buffer[0]) < 32))
|
||||
ptr_buffer[0] = '.';
|
||||
ptr_buffer++;
|
||||
}
|
||||
|
||||
strcpy (buffer->log_filename, log_path2);
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
free (log_path2);
|
||||
if (buffer->log_filename[strlen (buffer->log_filename) - 1] != DIR_SEPARATOR_CHAR)
|
||||
strcat (buffer->log_filename, DIR_SEPARATOR);
|
||||
|
||||
if (SERVER(buffer))
|
||||
{
|
||||
strcat (buffer->log_filename, SERVER(buffer)->name);
|
||||
strcat (buffer->log_filename, ".");
|
||||
}
|
||||
if (CHANNEL(buffer))
|
||||
{
|
||||
strcat (buffer->log_filename, CHANNEL(buffer)->name);
|
||||
strcat (buffer->log_filename, ".");
|
||||
}
|
||||
strcat (buffer->log_filename, "weechatlog");
|
||||
|
||||
buffer->log_file = fopen (buffer->log_filename, "a");
|
||||
if (!buffer->log_file)
|
||||
{
|
||||
weechat_log_printf (_("Unable to write log file for a buffer\n"));
|
||||
free (buffer->log_filename);
|
||||
return;
|
||||
}
|
||||
log_write (buffer, _("**** Beginning of log "));
|
||||
log_write_date (buffer);
|
||||
log_write (buffer, "****\n");
|
||||
seconds = time (NULL);
|
||||
date_tmp = localtime (&seconds);
|
||||
if (date_tmp)
|
||||
fprintf (weechat_log_file, "[%04d-%02d-%02d %02d:%02d:%02d] %s",
|
||||
date_tmp->tm_year + 1900, date_tmp->tm_mon + 1, date_tmp->tm_mday,
|
||||
date_tmp->tm_hour, date_tmp->tm_min, date_tmp->tm_sec,
|
||||
buffer);
|
||||
else
|
||||
fprintf (weechat_log_file, "%s", buffer);
|
||||
fflush (weechat_log_file);
|
||||
}
|
||||
|
||||
/*
|
||||
* log_end: ends a log
|
||||
* weechat_log_close: close log file
|
||||
*/
|
||||
|
||||
void
|
||||
log_end (t_gui_buffer *buffer)
|
||||
weechat_log_close ()
|
||||
{
|
||||
if (buffer->log_file)
|
||||
if (weechat_log_file)
|
||||
{
|
||||
flock (fileno (weechat_log_file), LOCK_UN);
|
||||
fclose (weechat_log_file);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_log_crash_rename: rename log file when crashing
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_log_crash_rename ()
|
||||
{
|
||||
char *oldname, *newname;
|
||||
|
||||
oldname = (char *) malloc (strlen (weechat_home) + 64);
|
||||
newname = (char *) malloc (strlen (weechat_home) + 64);
|
||||
if (oldname && newname)
|
||||
{
|
||||
log_write (buffer, _("**** End of log "));
|
||||
log_write_date (buffer);
|
||||
log_write (buffer, "****\n");
|
||||
fclose (buffer->log_file);
|
||||
buffer->log_file = NULL;
|
||||
}
|
||||
if (buffer->log_filename)
|
||||
free (buffer->log_filename);
|
||||
}
|
||||
|
@ -21,13 +21,11 @@
|
||||
#ifndef __WEECHAT_LOG_H
|
||||
#define __WEECHAT_LOG_H 1
|
||||
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
extern FILE *weechat_log_file;
|
||||
|
||||
extern void log_write_date (t_gui_buffer *);
|
||||
extern void log_write_line (t_gui_buffer *, char *);
|
||||
extern void log_write (t_gui_buffer *, char *);
|
||||
extern void log_start (t_gui_buffer *);
|
||||
extern void log_end (t_gui_buffer *);
|
||||
extern void weechat_log_init ();
|
||||
extern void weechat_log_close ();
|
||||
extern void weechat_log_printf (char *, ...);
|
||||
extern void weechat_log_crash_rename ();
|
||||
|
||||
#endif /* log.h */
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include "weechat.h"
|
||||
#include "session.h"
|
||||
#include "log.h"
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
|
@ -42,9 +42,7 @@
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
@ -63,11 +61,12 @@
|
||||
|
||||
#include "weechat.h"
|
||||
#include "backtrace.h"
|
||||
#include "weeconfig.h"
|
||||
#include "command.h"
|
||||
#include "fifo.h"
|
||||
#include "utf8.h"
|
||||
#include "log.h"
|
||||
#include "session.h"
|
||||
#include "utf8.h"
|
||||
#include "weeconfig.h"
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
@ -76,19 +75,18 @@
|
||||
#endif
|
||||
|
||||
|
||||
char *weechat_argv0 = NULL; /* WeeChat binary file name (argv[0]) */
|
||||
char *weechat_session = NULL; /* WeeChat session file (for /upgrade command) */
|
||||
time_t weechat_start_time; /* WeeChat start time (used by /uptime command) */
|
||||
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
|
||||
int sigsegv = 0; /* SIGSEGV received? */
|
||||
char *weechat_home = NULL; /* WeeChat home dir. (example: /home/toto/.weechat) */
|
||||
FILE *weechat_log_file = NULL; /* WeeChat log file (~/.weechat/weechat.log) */
|
||||
char *weechat_argv0 = NULL; /* WeeChat binary file name (argv[0]) */
|
||||
char *weechat_session = NULL; /* WeeChat session file (for /upgrade cmd) */
|
||||
time_t weechat_start_time; /* WeeChat start time (used by /uptime cmd) */
|
||||
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
|
||||
int sigsegv = 0; /* SIGSEGV received? */
|
||||
char *weechat_home = NULL; /* WeeChat home dir. (default: ~/.weechat) */
|
||||
|
||||
char *local_charset = NULL; /* local charset, for example: ISO-8859-1, UTF-8 */
|
||||
char *local_charset = NULL; /* local charset, for ex.: ISO-8859-1, UTF-8 */
|
||||
|
||||
int server_cmd_line; /* at least one server on WeeChat command line */
|
||||
int auto_connect; /* enabled by default, can by disabled on cmd line */
|
||||
int auto_load_plugins; /* enabled by default, can by disabled on cmd line */
|
||||
int server_cmd_line; /* at least 1 server on WeeChat command line */
|
||||
int auto_connect; /* enabled by default (cmd option to disable) */
|
||||
int auto_load_plugins; /* enabled by default (cmd option to disable) */
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */
|
||||
@ -197,49 +195,6 @@ ascii_strncasecmp (char *string1, char *string2, int max)
|
||||
return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_log_printf: displays a message in WeeChat log (<weechat_home>/weechat.log)
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_log_printf (char *message, ...)
|
||||
{
|
||||
static char buffer[4096];
|
||||
char *ptr_buffer;
|
||||
va_list argptr;
|
||||
static time_t seconds;
|
||||
struct tm *date_tmp;
|
||||
|
||||
if (!weechat_log_file)
|
||||
return;
|
||||
|
||||
va_start (argptr, message);
|
||||
vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
/* keep only valid chars */
|
||||
ptr_buffer = buffer;
|
||||
while (ptr_buffer[0])
|
||||
{
|
||||
if ((ptr_buffer[0] != '\n')
|
||||
&& (ptr_buffer[0] != '\r')
|
||||
&& ((unsigned char)(ptr_buffer[0]) < 32))
|
||||
ptr_buffer[0] = '.';
|
||||
ptr_buffer++;
|
||||
}
|
||||
|
||||
seconds = time (NULL);
|
||||
date_tmp = localtime (&seconds);
|
||||
if (date_tmp)
|
||||
fprintf (weechat_log_file, "[%04d-%02d-%02d %02d:%02d:%02d] %s",
|
||||
date_tmp->tm_year + 1900, date_tmp->tm_mon + 1, date_tmp->tm_mday,
|
||||
date_tmp->tm_hour, date_tmp->tm_min, date_tmp->tm_sec,
|
||||
buffer);
|
||||
else
|
||||
fprintf (weechat_log_file, "%s", buffer);
|
||||
fflush (weechat_log_file);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_iconv: convert string to another charset
|
||||
*/
|
||||
@ -834,35 +789,6 @@ weechat_init_vars ()
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_init_log: initialize log file
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_init_log ()
|
||||
{
|
||||
int filename_length;
|
||||
char *filename;
|
||||
|
||||
filename_length = strlen (weechat_home) + 64;
|
||||
filename =
|
||||
(char *) malloc (filename_length * sizeof (char));
|
||||
snprintf (filename, filename_length, "%s/" WEECHAT_LOG_NAME, weechat_home);
|
||||
|
||||
weechat_log_file = fopen (filename, "wt");
|
||||
if (!weechat_log_file
|
||||
|| (flock (fileno (weechat_log_file), LOCK_EX | LOCK_NB) != 0))
|
||||
{
|
||||
fprintf (stderr,
|
||||
_("%s unable to create/append to log file (%s/%s)\n"
|
||||
"If another WeeChat process is using this file, try to run WeeChat\n"
|
||||
"with another home using \"--dir\" command line option.\n"),
|
||||
WEECHAT_ERROR, weechat_home, WEECHAT_LOG_NAME);
|
||||
exit (1);
|
||||
}
|
||||
free (filename);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_config_read: read WeeChat config file
|
||||
*/
|
||||
@ -948,11 +874,7 @@ weechat_shutdown (int return_code, int crash)
|
||||
fifo_remove ();
|
||||
if (weechat_home)
|
||||
free (weechat_home);
|
||||
if (weechat_log_file)
|
||||
{
|
||||
flock (fileno (weechat_log_file), LOCK_UN);
|
||||
fclose (weechat_log_file);
|
||||
}
|
||||
weechat_log_close ();
|
||||
if (local_charset)
|
||||
free (local_charset);
|
||||
alias_free_all ();
|
||||
@ -1085,9 +1007,10 @@ weechat_sigsegv ()
|
||||
weechat_home);
|
||||
fprintf (stderr, "***\n");
|
||||
fprintf (stderr, "*** Please help WeeChat developers to fix this bug:\n");
|
||||
fprintf (stderr, "*** 1. if you have a core file, please run: gdb weechat-curses core\n");
|
||||
fprintf (stderr, "*** 1. If you have a core file, please run: gdb weechat-curses core\n");
|
||||
fprintf (stderr, "*** then issue \"bt\" command and send result to developers\n");
|
||||
fprintf (stderr, "*** 2. otherwise send backtrace displayed below and weechat.log\n");
|
||||
fprintf (stderr, "*** To enable core files with bash shell: ulimit -c 10000\n");
|
||||
fprintf (stderr, "*** 2. Otherwise send backtrace displayed below and weechat.log\n");
|
||||
fprintf (stderr, "*** (be careful, private info may be in this file since\n");
|
||||
fprintf (stderr, "*** part of chats are displayed, so remove lines if needed)\n\n");
|
||||
|
||||
@ -1125,7 +1048,7 @@ main (int argc, char *argv[])
|
||||
gui_keyboard_init (); /* init keyb. (default key bindings)*/
|
||||
weechat_parse_args (argc, argv); /* parse command line args */
|
||||
weechat_create_home_dirs (); /* create WeeChat directories */
|
||||
weechat_init_log (); /* init log file */
|
||||
weechat_log_init (); /* init log file */
|
||||
command_index_build (); /* build cmd index for completion */
|
||||
weechat_config_read (); /* read configuration */
|
||||
weechat_create_config_dirs (); /* create config directories */
|
||||
|
@ -98,7 +98,6 @@ extern char *weechat_argv0;
|
||||
extern time_t weechat_start_time;
|
||||
extern int quit_weechat;
|
||||
extern char *weechat_home;
|
||||
extern FILE *weechat_log_file;
|
||||
extern char *local_charset;
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
@ -109,7 +108,6 @@ extern void ascii_tolower (char *);
|
||||
extern void ascii_toupper (char *);
|
||||
extern int ascii_strcasecmp (char *, char *);
|
||||
extern int ascii_strncasecmp (char *, char *, int);
|
||||
extern void weechat_log_printf (char *, ...);
|
||||
extern char *weechat_iconv (char *, char *, char *);
|
||||
extern char *weechat_strreplace (char *, char *, char *);
|
||||
extern void weechat_dump (int);
|
||||
|
@ -1282,23 +1282,23 @@ config_change_log ()
|
||||
if (BUFFER_IS_SERVER(ptr_buffer))
|
||||
{
|
||||
if (cfg_log_auto_server && !ptr_buffer->log_file)
|
||||
log_start (ptr_buffer);
|
||||
gui_log_start (ptr_buffer);
|
||||
else if (!cfg_log_auto_server && ptr_buffer->log_file)
|
||||
log_end (ptr_buffer);
|
||||
gui_log_end (ptr_buffer);
|
||||
}
|
||||
if (BUFFER_IS_CHANNEL(ptr_buffer))
|
||||
{
|
||||
if (cfg_log_auto_channel && !ptr_buffer->log_file)
|
||||
log_start (ptr_buffer);
|
||||
gui_log_start (ptr_buffer);
|
||||
else if (!cfg_log_auto_channel && ptr_buffer->log_file)
|
||||
log_end (ptr_buffer);
|
||||
gui_log_end (ptr_buffer);
|
||||
}
|
||||
if (BUFFER_IS_PRIVATE(ptr_buffer))
|
||||
{
|
||||
if (cfg_log_auto_private && !ptr_buffer->log_file)
|
||||
log_start (ptr_buffer);
|
||||
gui_log_start (ptr_buffer);
|
||||
else if (!cfg_log_auto_private && ptr_buffer->log_file)
|
||||
log_end (ptr_buffer);
|
||||
gui_log_end (ptr_buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ lib_weechat_gui_common_a_SOURCES = gui-buffer.c \
|
||||
gui-common.c \
|
||||
gui-action.c \
|
||||
gui-keyboard.c \
|
||||
gui-log.c \
|
||||
gui-window.c \
|
||||
gui-panel.c \
|
||||
gui.h \
|
||||
|
@ -20,9 +20,7 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\"
|
||||
bin_PROGRAMS = weechat-curses
|
||||
|
||||
if PLUGINS
|
||||
weechat_curses_LDADD = ../gui-common.o ../gui-buffer.o \
|
||||
../gui-window.o ../gui-panel.o \
|
||||
../gui-keyboard.o ../gui-action.o \
|
||||
weechat_curses_LDADD = ../lib_weechat_gui_common.a \
|
||||
../../common/lib_weechat_main.a \
|
||||
../../irc/lib_weechat_irc.a \
|
||||
../../plugins/lib_weechat_plugins.a \
|
||||
@ -30,9 +28,7 @@ weechat_curses_LDADD = ../gui-common.o ../gui-buffer.o \
|
||||
$(NCURSES_LIBS) \
|
||||
$(GNUTLS_LFLAGS)
|
||||
else
|
||||
weechat_curses_LDADD = ../gui-common.o ../gui-buffer.o \
|
||||
../gui-window.o ../gui-panel.o \
|
||||
../gui-keyboard.o ../gui-action.o \
|
||||
weechat_curses_LDADD = ../lib_weechat_gui_common.a \
|
||||
../../common/lib_weechat_main.a \
|
||||
../../irc/lib_weechat_irc.a \
|
||||
$(PLUGINS_LIBS) \
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "../../common/weechat.h"
|
||||
#include "../gui.h"
|
||||
#include "../../common/hotlist.h"
|
||||
#include "../../common/log.h"
|
||||
#include "../../common/weeconfig.h"
|
||||
#include "gui-curses.h"
|
||||
|
||||
|
@ -20,9 +20,7 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(GTK_CFLAGS)
|
||||
bin_PROGRAMS = weechat-gtk
|
||||
|
||||
if PLUGINS
|
||||
weechat_gtk_LDADD = ../gui-common.o ../gui-buffer.o \
|
||||
../gui-window.o ../gui-panel.o \
|
||||
../gui-keyboard.o ../gui-action.o \
|
||||
weechat_gtk_LDADD = ../lib_weechat_gui_common.a \
|
||||
../../common/lib_weechat_main.a \
|
||||
../../irc/lib_weechat_irc.a \
|
||||
../../plugins/lib_weechat_plugins.a \
|
||||
@ -30,9 +28,7 @@ weechat_gtk_LDADD = ../gui-common.o ../gui-buffer.o \
|
||||
$(GTK_LIBS) \
|
||||
$(GNUTLS_LFLAGS)
|
||||
else
|
||||
weechat_gtk_LDADD = ../gui-common.o ../gui-buffer.o \
|
||||
../gui-window.o ../gui-panel.o \
|
||||
../gui-keyboard.o ../gui-action.o \
|
||||
weechat_gtk_LDADD = ../lib_weechat_gui_common.a \
|
||||
../../common/lib_weechat_main.a \
|
||||
../../irc/lib_weechat_irc.a \
|
||||
$(PLUGINS_LIBS) \
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "../../common/weechat.h"
|
||||
#include "../gui.h"
|
||||
#include "../../common/hotlist.h"
|
||||
#include "../../common/log.h"
|
||||
#include "../../common/weeconfig.h"
|
||||
#include "gui-gtk.h"
|
||||
|
||||
|
@ -98,7 +98,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int type,
|
||||
if (cfg_look_one_server_buffer && server && !channel)
|
||||
gui_buffers->all_servers = 1;
|
||||
if (cfg_log_auto_server)
|
||||
log_start (gui_buffers);
|
||||
gui_log_start (gui_buffers);
|
||||
return gui_buffers;
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int type,
|
||||
if ((cfg_log_auto_server && BUFFER_IS_SERVER(new_buffer))
|
||||
|| (cfg_log_auto_channel && BUFFER_IS_CHANNEL(new_buffer))
|
||||
|| (cfg_log_auto_private && BUFFER_IS_PRIVATE(new_buffer)))
|
||||
log_start (new_buffer);
|
||||
gui_log_start (new_buffer);
|
||||
|
||||
/* init input buffer */
|
||||
new_buffer->has_input = (new_buffer->type == BUFFER_TYPE_STANDARD) ? 1 : 0;
|
||||
@ -479,7 +479,7 @@ gui_buffer_free (t_gui_buffer *buffer, int switch_to_another)
|
||||
|
||||
/* close log if opened */
|
||||
if (buffer->log_file)
|
||||
log_end (buffer);
|
||||
gui_log_end (buffer);
|
||||
|
||||
if (buffer->input_buffer)
|
||||
free (buffer->input_buffer);
|
||||
|
@ -193,18 +193,18 @@ gui_add_to_line (t_gui_buffer *buffer, int type, char *nick, char *message)
|
||||
}
|
||||
if (buffer->line_complete && buffer->log_file && buffer->last_line->log_write)
|
||||
{
|
||||
log_write_date (buffer);
|
||||
gui_log_write_date (buffer);
|
||||
if (buffer->last_line->nick)
|
||||
{
|
||||
log_write (buffer, "<");
|
||||
log_write (buffer, buffer->last_line->nick);
|
||||
log_write (buffer, "> ");
|
||||
gui_log_write (buffer, "<");
|
||||
gui_log_write (buffer, buffer->last_line->nick);
|
||||
gui_log_write (buffer, "> ");
|
||||
}
|
||||
if (buffer->last_line->ofs_start_message >= 0)
|
||||
log_write_line (buffer,
|
||||
buffer->last_line->data + buffer->last_line->ofs_start_message);
|
||||
gui_log_write_line (buffer,
|
||||
buffer->last_line->data + buffer->last_line->ofs_start_message);
|
||||
else
|
||||
log_write_line (buffer, buffer->last_line->data);
|
||||
gui_log_write_line (buffer, buffer->last_line->data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "../common/weechat.h"
|
||||
#include "gui.h"
|
||||
#include "../common/command.h"
|
||||
#include "../common/log.h"
|
||||
|
||||
#ifdef PLUGINS
|
||||
#include "../plugins/plugins.h"
|
||||
|
188
weechat/src/gui/gui-log.c
Normal file
188
weechat/src/gui/gui-log.c
Normal file
@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2006 by FlashCode <flashcode@flashtux.org>
|
||||
* See README for License detail, AUTHORS for developers list.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* gui-log.c: log buffers to files */
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "gui.h"
|
||||
#include "../common/log.h"
|
||||
#include "../common/weeconfig.h"
|
||||
|
||||
|
||||
/*
|
||||
* gui_log_write_date: writes date to log file
|
||||
*/
|
||||
|
||||
void
|
||||
gui_log_write_date (t_gui_buffer *buffer)
|
||||
{
|
||||
static char buf_time[256];
|
||||
static time_t seconds;
|
||||
struct tm *date_tmp;
|
||||
|
||||
if (buffer->log_file)
|
||||
{
|
||||
seconds = time (NULL);
|
||||
date_tmp = localtime (&seconds);
|
||||
if (date_tmp)
|
||||
{
|
||||
strftime (buf_time, sizeof (buf_time) - 1, cfg_log_timestamp, date_tmp);
|
||||
fprintf (buffer->log_file, "%s ", buf_time);
|
||||
fflush (buffer->log_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_log_write_line: writes a line to log file
|
||||
*/
|
||||
|
||||
void
|
||||
gui_log_write_line (t_gui_buffer *buffer, char *message)
|
||||
{
|
||||
char *msg_no_color;
|
||||
|
||||
if (buffer->log_file)
|
||||
{
|
||||
msg_no_color = (char *)gui_color_decode ((unsigned char *)message, 0);
|
||||
fprintf (buffer->log_file, "%s\n",
|
||||
(msg_no_color) ? msg_no_color : message);
|
||||
fflush (buffer->log_file);
|
||||
if (msg_no_color)
|
||||
free (msg_no_color);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_log_write: writes a message to log file
|
||||
*/
|
||||
|
||||
void
|
||||
gui_log_write (t_gui_buffer *buffer, char *message)
|
||||
{
|
||||
char *msg_no_color;
|
||||
|
||||
if (buffer->log_file)
|
||||
{
|
||||
msg_no_color = (char *)gui_color_decode ((unsigned char *)message, 0);
|
||||
fprintf (buffer->log_file, "%s",
|
||||
(msg_no_color) ? msg_no_color : message);
|
||||
fflush (buffer->log_file);
|
||||
if (msg_no_color)
|
||||
free (msg_no_color);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_log_start: starts a log
|
||||
*/
|
||||
|
||||
void
|
||||
gui_log_start (t_gui_buffer *buffer)
|
||||
{
|
||||
int length;
|
||||
char *log_path, *log_path2;
|
||||
|
||||
log_path = weechat_strreplace (cfg_log_path, "~", getenv ("HOME"));
|
||||
log_path2 = weechat_strreplace (log_path, "%h", weechat_home);
|
||||
if (!log_path || !log_path2)
|
||||
{
|
||||
weechat_log_printf (_("Not enough memory to write log file for a buffer\n"));
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
free (log_path2);
|
||||
return;
|
||||
}
|
||||
length = strlen (log_path2) + 64;
|
||||
if (SERVER(buffer))
|
||||
length += strlen (SERVER(buffer)->name);
|
||||
if (CHANNEL(buffer))
|
||||
length += strlen (CHANNEL(buffer)->name);
|
||||
|
||||
buffer->log_filename = (char *) malloc (length);
|
||||
if (!buffer->log_filename)
|
||||
{
|
||||
weechat_log_printf (_("Not enough memory to write log file for a buffer\n"));
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
free (log_path2);
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy (buffer->log_filename, log_path2);
|
||||
if (log_path)
|
||||
free (log_path);
|
||||
if (log_path2)
|
||||
free (log_path2);
|
||||
if (buffer->log_filename[strlen (buffer->log_filename) - 1] != DIR_SEPARATOR_CHAR)
|
||||
strcat (buffer->log_filename, DIR_SEPARATOR);
|
||||
|
||||
if (SERVER(buffer))
|
||||
{
|
||||
strcat (buffer->log_filename, SERVER(buffer)->name);
|
||||
strcat (buffer->log_filename, ".");
|
||||
}
|
||||
if (CHANNEL(buffer))
|
||||
{
|
||||
strcat (buffer->log_filename, CHANNEL(buffer)->name);
|
||||
strcat (buffer->log_filename, ".");
|
||||
}
|
||||
strcat (buffer->log_filename, "weechatlog");
|
||||
|
||||
buffer->log_file = fopen (buffer->log_filename, "a");
|
||||
if (!buffer->log_file)
|
||||
{
|
||||
weechat_log_printf (_("Unable to write log file for a buffer\n"));
|
||||
free (buffer->log_filename);
|
||||
return;
|
||||
}
|
||||
gui_log_write (buffer, _("**** Beginning of log "));
|
||||
gui_log_write_date (buffer);
|
||||
gui_log_write (buffer, "****\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_log_end: ends a log
|
||||
*/
|
||||
|
||||
void
|
||||
gui_log_end (t_gui_buffer *buffer)
|
||||
{
|
||||
if (buffer->log_file)
|
||||
{
|
||||
gui_log_write (buffer, _("**** End of log "));
|
||||
gui_log_write_date (buffer);
|
||||
gui_log_write (buffer, "****\n");
|
||||
fclose (buffer->log_file);
|
||||
buffer->log_file = NULL;
|
||||
}
|
||||
if (buffer->log_filename)
|
||||
free (buffer->log_filename);
|
||||
}
|
@ -27,6 +27,7 @@
|
||||
#include "gui-window.h"
|
||||
#include "gui-keyboard.h"
|
||||
|
||||
|
||||
#define gui_printf(buffer, fmt, argz...) \
|
||||
gui_printf_internal(buffer, 1, MSG_TYPE_INFO, NULL, fmt, ##argz)
|
||||
|
||||
@ -42,6 +43,7 @@
|
||||
#define gui_printf_nolog_notime(buffer, fmt, argz...) \
|
||||
gui_printf_internal(buffer, 0, MSG_TYPE_NOLOG, NULL, fmt, ##argz)
|
||||
|
||||
|
||||
typedef struct t_gui_infobar t_gui_infobar;
|
||||
|
||||
struct t_gui_infobar
|
||||
@ -163,6 +165,13 @@ extern int gui_keyboard_pressed (char *);
|
||||
extern void gui_keyboard_free (t_gui_key *);
|
||||
extern void gui_keyboard_free_all ();
|
||||
|
||||
/* log */
|
||||
extern void gui_log_write_date (t_gui_buffer *);
|
||||
extern void gui_log_write_line (t_gui_buffer *, char *);
|
||||
extern void gui_log_write (t_gui_buffer *, char *);
|
||||
extern void gui_log_start (t_gui_buffer *);
|
||||
extern void gui_log_end (t_gui_buffer *);
|
||||
|
||||
/* other */
|
||||
extern void gui_infobar_printf (int, int, char *, ...);
|
||||
extern void gui_infobar_printf_from_buffer (t_gui_buffer *, int, int, char *, char *, ...);
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
#include "../common/log.h"
|
||||
#include "../common/utf8.h"
|
||||
#include "../common/weeconfig.h"
|
||||
#include "../gui/gui.h"
|
||||
|
@ -39,8 +39,9 @@
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
#include "../common/weeconfig.h"
|
||||
#include "../common/log.h"
|
||||
#include "../common/hotlist.h"
|
||||
#include "../common/weeconfig.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
#include "../common/command.h"
|
||||
#include "../common/log.h"
|
||||
|
||||
|
||||
char *ignore_types[] =
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
#include "../common/log.h"
|
||||
#include "../common/weeconfig.h"
|
||||
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
#include "../common/log.h"
|
||||
#include "../common/weeconfig.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
|
@ -258,7 +258,7 @@ weechat_plugin_log (t_weechat_plugin *plugin,
|
||||
va_start (argptr, message);
|
||||
vsnprintf (buf, sizeof (buf) - 1, message, argptr);
|
||||
va_end (argptr);
|
||||
log_write_line (ptr_buffer, buf);
|
||||
gui_log_write_line (ptr_buffer, buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user