Added logger plugin

This commit is contained in:
Sebastien Helleu 2007-11-11 14:36:34 +01:00
parent 4478777876
commit cdc08d6fc3
16 changed files with 780 additions and 326 deletions

View File

@ -36,15 +36,16 @@ OPTION(ENABLE_GTK "Enable GTK interface")
OPTION(DISABLE_NLS "Disable Native Language Support")
OPTION(DISABLE_GNUTLS "Disable SSLv3/TLS connection support")
OPTION(DISABLE_IRC "Disable IRC plugin")
OPTION(DISABLE_ASPELL "Disable Aspell plugin")
OPTION(DISABLE_CHARSET "Disable Charset plugin")
OPTION(DISABLE_FIFO "Disable FIFO plugin")
OPTION(DISABLE_LOGGER "Disable Logger plugin")
OPTION(DISABLE_TRIGGER "Disable Trigger plugin")
OPTION(DISABLE_SCRIPTS "Disable script plugins")
OPTION(DISABLE_PERL "Disable Perl scripting language")
OPTION(DISABLE_PYTHON "Disable Python scripting language")
OPTION(DISABLE_RUBY "Disable Ruby scripting language")
OPTION(DISABLE_LUA "Disable Lua scripting language")
OPTION(DISABLE_ASPELL "Disable Aspell plugin")
OPTION(DISABLE_CHARSET "Disable Charset plugin")
OPTION(DISABLE_FIFO "Disable FIFO plugin")
OPTION(DISABLE_TRIGGER "Disable Trigger plugin")
OPTION(ENABLE_DEMO "Enable Demo plugin")
OPTION(DISABLE_DOC "Disable Doc")

View File

@ -92,14 +92,15 @@ AH_VERBATIM([PREFIX], [#undef PREFIX])
AH_VERBATIM([WEECHAT_LIBDIR], [#undef WEECHAT_LIBDIR])
AH_VERBATIM([WEECHAT_SHAREDIR], [#undef WEECHAT_SHAREDIR])
AH_VERBATIM([PLUGIN_IRC], [#undef PLUGIN_IRC])
AH_VERBATIM([PLUGIN_ASPELL], [#undef PLUGIN_ASPELL])
AH_VERBATIM([PLUGIN_CHARSET], [#undef PLUGIN_CHARSET])
AH_VERBATIM([PLUGIN_FIFO], [#undef PLUGIN_FIFO])
AH_VERBATIM([PLUGIN_LOGGER], [#undef PLUGIN_LOGGER])
AH_VERBATIM([PLUGIN_TRIGGER], [#undef PLUGIN_TRIGGER])
AH_VERBATIM([PLUGIN_PERL], [#undef PLUGIN_PERL])
AH_VERBATIM([PLUGIN_PYTHON], [#undef PLUGIN_PYTHON])
AH_VERBATIM([PLUGIN_RUBY], [#undef PLUGIN_RUBY])
AH_VERBATIM([PLUGIN_LUA], [#undef PLUGIN_LUA])
AH_VERBATIM([PLUGIN_ASPELL], [#undef PLUGIN_ASPELL])
AH_VERBATIM([PLUGIN_CHARSET], [#undef PLUGIN_CHARSET])
AH_VERBATIM([PLUGIN_FIFO], [#undef PLUGIN_FIFO])
AH_VERBATIM([PLUGIN_TRIGGER], [#undef PLUGIN_TRIGGER])
AH_VERBATIM([PLUGIN_DEMO], [#undef PLUGIN_DEMO])
AH_VERBATIM([HAVE_GNUTLS], [#undef HAVE_GNUTLS])
AH_VERBATIM([HAVE_FLOCK], [#undef HAVE_FLOCK])
@ -113,6 +114,11 @@ AC_ARG_ENABLE(gtk, [ --enable-gtk Turn on Gtk interface (d
AC_ARG_ENABLE(qt, [ --enable-qt Turn on Qt interface (default=off)],enable_qt=$enableval,enable_qt=no)
AC_ARG_ENABLE(gnutls, [ --disable-gnutls Turn off gnutls support (default=compiled if found)],enable_gnutls=$enableval,enable_gnutls=yes)
AC_ARG_ENABLE(irc, [ --disable-irc Turn off IRC plugin (default=compiled)],enable_irc=$enableval,enable_irc=yes)
AC_ARG_ENABLE(aspell, [ --disable-aspell Turn off Aspell plugin (default=compiled if found)],enable_aspell=$enableval,enable_aspell=yes)
AC_ARG_ENABLE(charset, [ --disable-charset Turn off Charset plugin (default=compiled if found)],enable_charset=$enableval,enable_charset=yes)
AC_ARG_ENABLE(fifo, [ --disable-fifo Turn off Fifo plugin (default=compiled)],enable_fifo=$enableval,enable_fifo=yes)
AC_ARG_ENABLE(logger, [ --disable-logger Turn off Logger plugin (default=compiled)],enable_logger=$enableval,enable_logger=yes)
AC_ARG_ENABLE(trigger, [ --disable-trigger Turn off Trigger plugin (default=compiled if found)],enable_trigger=$enableval,enable_trigger=yes)
AC_ARG_ENABLE(scripts, [ --disable-scripts Turn off script plugins (default=compiled if found)],enable_scripts=$enableval,enable_scripts=yes)
AC_ARG_ENABLE(perl, [ --disable-perl Turn off Perl script plugin (default=compiled if found)],enable_perl=$enableval,enable_perl=yes)
AC_ARG_ENABLE(python, [ --disable-python Turn off Python script plugin (default=compiled if found)],enable_python=$enableval,enable_python=yes)
@ -121,10 +127,6 @@ AC_ARG_ENABLE(lua, [ --disable-lua Turn off Lua script plug
AC_ARG_WITH(lua-inc, [ --with-lua-inc=DIR, Lua include files are in DIR (default=autodetect)],lua_inc=$withval,lua_inc='')
AC_ARG_WITH(lua-lib, [ --with-lua-lib=DIR, Lua library files are in DIR (default=autodetect)],lua_lib=$withval,lua_lib='')
AC_ARG_WITH(lua-suffix, [ --with-lua-suffix=ARG Lua is suffixed with ARG (default=autodetect)],lua_suffix=$withval,lua_suffix='')
AC_ARG_ENABLE(aspell, [ --disable-aspell Turn off Aspell plugin (default=compiled if found)],enable_aspell=$enableval,enable_aspell=yes)
AC_ARG_ENABLE(charset, [ --disable-charset Turn off Charset plugin (default=compiled if found)],enable_charset=$enableval,enable_charset=yes)
AC_ARG_ENABLE(fifo, [ --disable-fifo Turn off Fifo plugin (default=compiled if found)],enable_fifo=$enableval,enable_fifo=yes)
AC_ARG_ENABLE(trigger, [ --disable-trigger Turn off Trigger plugin (default=compiled if found)],enable_trigger=$enableval,enable_trigger=yes)
AC_ARG_ENABLE(demo, [ --enable-demo Turn on Demo plugin (default=off)],enable_demo=$enableval,enable_demo=no)
AC_ARG_WITH(doc_xsl_prefix, [ --with-doc-xsl-prefix=DIR Docbook html/chunk.xsl is in DIR (default=autodetect)],doc_xsl_prefix=$withval,doc_xsl_prefix='')
AC_ARG_WITH(debug, [ --with-debug Debugging: 0=no debug, 1=debug compilation, 2=debug compilation + verbose msgs (default=1)],debug=$withval,debug=1)
@ -271,7 +273,7 @@ if test "x$enable_scripts" = "xno" ; then
enable_lua="no"
fi
# ----------------------------------- irc --------------------------------------
# ------------------------------------ irc -------------------------------------
if test "x$enable_irc" = "xyes" ; then
AC_DEFINE(PLUGIN_IRC)
@ -279,6 +281,86 @@ else
not_asked="$not_asked irc"
fi
# ---------------------------------- aspell ------------------------------------
if test "x$enable_aspell" = "xyes" ; then
ASPELL_CFLAGS=""
ASPELL_LFLAGS=""
AC_CHECK_HEADER(aspell.h,ac_found_aspell_header="yes",ac_found_aspell_header="no")
AC_CHECK_LIB(aspell,new_aspell_speller,ac_found_aspell_lib="yes",ac_found_aspell_lib="no")
AC_MSG_CHECKING(for aspell headers and librairies)
if test "x$ac_found_aspell_header" = "xno" -o "x$ac_found_aspell_lib" = "xno" ; then
AC_MSG_RESULT(no)
AC_MSG_WARN([
*** Aspell headers and/or libraries couldn't be found in your system.
*** Try to install them with your software package manager.
*** WeeChat will be built without Aspell support.])
enable_aspell="no"
not_found="$not_found aspell"
else
AC_MSG_RESULT(yes)
ASPELL_LFLAGS="$ASPELL_LFLAGS -laspell"
fi
else
not_asked="$not_asked aspell"
fi
if test "x$enable_aspell" = "xyes" ; then
AC_SUBST(ASPELL_CFLAGS)
AC_SUBST(ASPELL_LFLAGS)
AC_DEFINE(PLUGIN_ASPELL)
fi
# --------------------------------- charset ------------------------------------
if test "x$enable_charset" = "xyes" ; then
CHARSET_CFLAGS=""
CHARSET_LFLAGS="$ICONV_LFLAGS"
AC_SUBST(CHARSET_CFLAGS)
AC_SUBST(CHARSET_LFLAGS)
AC_DEFINE(PLUGIN_CHARSET)
else
not_asked="$not_asked charset"
fi
# ---------------------------------- fifo --------------------------------------
if test "x$enable_fifo" = "xyes" ; then
FIFO_CFLAGS=""
FIFO_LFLAGS=""
AC_SUBST(FIFO_CFLAGS)
AC_SUBST(FIFO_LFLAGS)
AC_DEFINE(PLUGIN_FIFO)
else
not_asked="$not_asked fifo"
fi
# --------------------------------- logger -------------------------------------
if test "x$enable_logger" = "xyes" ; then
LOGGER_CFLAGS=""
LOGGER_LFLAGS=""
AC_SUBST(LOGGER_CFLAGS)
AC_SUBST(LOGGER_LFLAGS)
AC_DEFINE(PLUGIN_LOGGER)
else
not_asked="$not_asked logger"
fi
# --------------------------------- trigger ------------------------------------
if test "x$enable_trigger" = "xyes" ; then
TRIGGER_CFLAGS=""
TRIGGER_LFLAGS=""
AC_SUBST(TRIGGER_CFLAGS)
AC_SUBST(TRIGGER_LFLAGS)
AC_DEFINE(PLUGIN_TRIGGER)
else
not_asked="$not_asked trigger"
fi
# ---------------------------------- perl --------------------------------------
PERL_VERSION=
@ -556,75 +638,6 @@ if test "x$enable_lua" = "xyes" ; then
AC_DEFINE(PLUGIN_LUA)
fi
# --------------------------------- aspell -------------------------------------
if test "x$enable_aspell" = "xyes" ; then
ASPELL_CFLAGS=""
ASPELL_LFLAGS=""
AC_CHECK_HEADER(aspell.h,ac_found_aspell_header="yes",ac_found_aspell_header="no")
AC_CHECK_LIB(aspell,new_aspell_speller,ac_found_aspell_lib="yes",ac_found_aspell_lib="no")
AC_MSG_CHECKING(for aspell headers and librairies)
if test "x$ac_found_aspell_header" = "xno" -o "x$ac_found_aspell_lib" = "xno" ; then
AC_MSG_RESULT(no)
AC_MSG_WARN([
*** Aspell headers and/or libraries couldn't be found in your system.
*** Try to install them with your software package manager.
*** WeeChat will be built without Aspell support.])
enable_aspell="no"
not_found="$not_found aspell"
else
AC_MSG_RESULT(yes)
ASPELL_LFLAGS="$ASPELL_LFLAGS -laspell"
fi
else
not_asked="$not_asked aspell"
fi
if test "x$enable_aspell" = "xyes" ; then
AC_SUBST(ASPELL_CFLAGS)
AC_SUBST(ASPELL_LFLAGS)
AC_DEFINE(PLUGIN_ASPELL)
fi
# --------------------------------- charset ------------------------------------
if test "x$enable_charset" = "xyes" ; then
CHARSET_CFLAGS=""
CHARSET_LFLAGS=""
CHARSET_LFLAGS="$CHARSET_LFLAGS $ICONV_LFLAGS"
AC_SUBST(CHARSET_CFLAGS)
AC_SUBST(CHARSET_LFLAGS)
AC_DEFINE(PLUGIN_CHARSET)
else
not_asked="$not_asked charset"
fi
# ---------------------------------- fifo --------------------------------------
if test "x$enable_fifo" = "xyes" ; then
FIFO_CFLAGS=""
FIFO_LFLAGS=""
AC_SUBST(FIFO_CFLAGS)
AC_SUBST(FIFO_LFLAGS)
AC_DEFINE(PLUGIN_FIFO)
else
not_asked="$not_asked fifo"
fi
# --------------------------------- trigger ------------------------------------
if test "x$enable_trigger" = "xyes" ; then
TRIGGER_CFLAGS=""
TRIGGER_LFLAGS=""
AC_SUBST(TRIGGER_CFLAGS)
AC_SUBST(TRIGGER_LFLAGS)
AC_DEFINE(PLUGIN_TRIGGER)
else
not_asked="$not_asked trigger"
fi
# ---------------------------------- demo --------------------------------------
if test "x$enable_demo" = "xyes" ; then
@ -820,14 +833,15 @@ AM_CONDITIONAL(GUI_WXWIDGETS, test "$enable_wxwidgets" = "yes")
AM_CONDITIONAL(GUI_GTK, test "$enable_gtk" = "yes")
AM_CONDITIONAL(GUI_QT, test "$enable_qt" = "yes")
AM_CONDITIONAL(PLUGIN_IRC, test "$enable_irc" = "yes")
AM_CONDITIONAL(PLUGIN_ASPELL, test "$enable_aspell" = "yes")
AM_CONDITIONAL(PLUGIN_CHARSET, test "$enable_charset" = "yes")
AM_CONDITIONAL(PLUGIN_FIFO, test "$enable_fifo" = "yes")
AM_CONDITIONAL(PLUGIN_LOGGER, test "$enable_logger" = "yes")
AM_CONDITIONAL(PLUGIN_TRIGGER, test "$enable_trigger" = "yes")
AM_CONDITIONAL(PLUGIN_PERL, test "$enable_perl" = "yes")
AM_CONDITIONAL(PLUGIN_PYTHON, test "$enable_python" = "yes")
AM_CONDITIONAL(PLUGIN_RUBY, test "$enable_ruby" = "yes")
AM_CONDITIONAL(PLUGIN_LUA, test "$enable_lua" = "yes")
AM_CONDITIONAL(PLUGIN_ASPELL, test "$enable_aspell" = "yes")
AM_CONDITIONAL(PLUGIN_CHARSET, test "$enable_charset" = "yes")
AM_CONDITIONAL(PLUGIN_FIFO, test "$enable_fifo" = "yes")
AM_CONDITIONAL(PLUGIN_TRIGGER, test "$enable_trigger" = "yes")
AM_CONDITIONAL(PLUGIN_DEMO, test "$enable_demo" = "yes")
AM_CONDITIONAL(HAVE_GNUTLS, test "$enable_gnutls" = "yes")
AM_CONDITIONAL(HAVE_FLOCK, test "$enable_flock" = "yes")
@ -847,15 +861,16 @@ AC_OUTPUT([Makefile
src/core/Makefile
src/plugins/Makefile
src/plugins/irc/Makefile
src/plugins/aspell/Makefile
src/plugins/charset/Makefile
src/plugins/fifo/Makefile
src/plugins/logger/Makefile
src/plugins/trigger/Makefile
src/plugins/scripts/Makefile
src/plugins/scripts/perl/Makefile
src/plugins/scripts/python/Makefile
src/plugins/scripts/ruby/Makefile
src/plugins/scripts/lua/Makefile
src/plugins/aspell/Makefile
src/plugins/charset/Makefile
src/plugins/fifo/Makefile
src/plugins/trigger/Makefile
src/plugins/demo/Makefile
src/gui/Makefile
src/gui/curses/Makefile
@ -893,6 +908,21 @@ listplugins=""
if test "x$enable_irc" = "xyes" ; then
listplugins="$listplugins irc"
fi
if test "x$enable_aspell" = "xyes"; then
listplugins="$listplugins aspell"
fi
if test "x$enable_charset" = "xyes"; then
listplugins="$listplugins charset"
fi
if test "x$enable_fifo" = "xyes"; then
listplugins="$listplugins fifo"
fi
if test "x$enable_logger" = "xyes"; then
listplugins="$listplugins logger"
fi
if test "x$enable_trigger" = "xyes"; then
listplugins="$listplugins trigger"
fi
if test "x$enable_perl" = "xyes"; then
listplugins="$listplugins perl($PERL_VERSION)"
fi
@ -905,18 +935,6 @@ fi
if test "x$enable_lua" = "xyes"; then
listplugins="$listplugins lua($LUA_VERSION)"
fi
if test "x$enable_aspell" = "xyes"; then
listplugins="$listplugins aspell"
fi
if test "x$enable_charset" = "xyes"; then
listplugins="$listplugins charset"
fi
if test "x$enable_fifo" = "xyes"; then
listplugins="$listplugins fifo"
fi
if test "x$enable_trigger" = "xyes"; then
listplugins="$listplugins trigger"
fi
if test "x$enable_demo" = "xyes"; then
listplugins="$listplugins demo"
fi

View File

@ -21,9 +21,8 @@ ENDIF(NOT DISABLE_NCURSES)
SET(LIB_GUI_COMMON_SRC gui-action.c gui-action.h gui-buffer.c gui-buffer.h
gui-chat.c gui-chat.h gui-color.c gui-color.h gui-completion.c gui-completion.h
gui-history.c gui-history.h gui-hotlist.c gui-hotlist.h gui-infobar.c
gui-infobar.h gui-input.c gui-input.h gui-keyboard.c gui-keyboard.h gui-log.c
gui-log.h gui-main.h gui-nicklist.c gui-nicklist.h gui-status.h gui-window.c
gui-window.h)
gui-infobar.h gui-input.c gui-input.h gui-keyboard.c gui-keyboard.h gui-main.h
gui-nicklist.c gui-nicklist.h gui-status.h gui-window.c gui-window.h)
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})
ADD_LIBRARY(weechat_gui_common STATIC ${LIB_GUI_COMMON_SRC})

View File

@ -38,8 +38,6 @@ lib_weechat_gui_common_a_SOURCES = gui-action.c \
gui-input.h \
gui-keyboard.c \
gui-keyboard.h \
gui-log.c \
gui-log.h \
gui-main.h \
gui-status.h \
gui-window.c \

View File

@ -39,7 +39,6 @@
#include "gui-input.h"
#include "gui-main.h"
#include "gui-nicklist.h"
#include "gui-log.h"
#include "gui-status.h"
#include "gui-window.h"
#include "../core/wee-command.h"
@ -98,10 +97,6 @@ gui_buffer_new (void *plugin, char *category, char *name)
new_buffer->notify_level = GUI_BUFFER_NOTIFY_LEVEL_DEFAULT;
new_buffer->num_displayed = 0;
/* create/append to log file */
new_buffer->log_filename = NULL;
new_buffer->log_file = NULL;
/* title */
new_buffer->title = NULL;
@ -240,23 +235,6 @@ gui_buffer_set_name (struct t_gui_buffer *buffer, char *name)
}
}
/*
* gui_buffer_set_log: set log file for a buffer
*/
void
gui_buffer_set_log (struct t_gui_buffer *buffer, char *log_filename)
{
if (buffer->log_file)
gui_log_end (buffer);
if (log_filename)
{
buffer->log_filename = strdup (log_filename);
gui_log_start (buffer);
}
}
/*
* gui_buffer_set_title: set title for a buffer
*/
@ -327,10 +305,6 @@ gui_buffer_set (struct t_gui_buffer *buffer, char *property, char *value)
gui_buffer_set_name (buffer, value);
gui_status_draw (buffer, 1);
}
else if (string_strcasecmp (property, "log") == 0)
{
gui_buffer_set_log (buffer, value);
}
else if (string_strcasecmp (property, "title") == 0)
{
gui_buffer_set_title (buffer, value);
@ -632,10 +606,6 @@ gui_buffer_free (struct t_gui_buffer *buffer, int switch_to_another)
gui_chat_line_free (buffer->lines);
buffer->lines = ptr_line;
}
/* close log if opened */
if (buffer->log_file)
gui_log_end (buffer);
}
if (buffer->input_buffer)
@ -984,8 +954,6 @@ gui_buffer_print_log ()
weechat_log_printf (" type . . . . . . . . . : %d\n", ptr_buffer->type);
weechat_log_printf (" notify_level . . . . . : %d\n", ptr_buffer->notify_level);
weechat_log_printf (" num_displayed. . . . . : %d\n", ptr_buffer->num_displayed);
weechat_log_printf (" log_filename . . . . . : '%s'\n", ptr_buffer->log_filename);
weechat_log_printf (" log_file . . . . . . . : 0x%X\n", ptr_buffer->log_file);
weechat_log_printf (" title. . . . . . . . . : '%s'\n", ptr_buffer->title);
weechat_log_printf (" lines. . . . . . . . . : 0x%X\n", ptr_buffer->lines);
weechat_log_printf (" last_line. . . . . . . : 0x%X\n", ptr_buffer->last_line);

View File

@ -75,10 +75,6 @@ struct t_gui_buffer
/* 3 = highlight + msg + join/part */
int num_displayed; /* number of windows displaying buf. */
/* logging */
char *log_filename; /* filename for saving content */
FILE *log_file; /* file descriptor for log */
/* buffer title */
char *title; /* buffer title */

View File

@ -1,150 +0,0 @@
/*
* Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/* 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 "../core/weechat.h"
#include "../core/wee-config.h"
#include "../core/wee-log.h"
#include "../core/wee-string.h"
#include "gui-log.h"
/*
* gui_log_write_date: writes date to log file
*/
void
gui_log_write_date (struct 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_time_format, 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 (struct t_gui_buffer *buffer, char *message)
{
char *msg_no_color;
if (buffer->log_file)
{
msg_no_color = (char *)gui_color_decode ((unsigned char *)message);
string_iconv_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 (struct t_gui_buffer *buffer, char *message)
{
char *msg_no_color;
if (buffer->log_file)
{
msg_no_color = (char *)gui_color_decode ((unsigned char *)message);
string_iconv_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 (struct t_gui_buffer *buffer)
{
if (buffer->log_filename)
{
buffer->log_file = fopen (buffer->log_filename, "a");
if (!buffer->log_file)
{
weechat_log_printf (_("Unable to write log file \"%s\"\n"),
buffer->log_filename);
gui_chat_printf (NULL,
_("%sError: Unable to write log file \"%s\"\n"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
buffer->log_filename);
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 (struct 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);
buffer->log_filename = NULL;
}
}

View File

@ -28,10 +28,6 @@ IF(NOT DISABLE_IRC)
ADD_SUBDIRECTORY( irc )
ENDIF(NOT DISABLE_IRC)
IF(NOT DISABLE_PERL AND NOT DISABLE_PYTHON AND NOT DISABLE_RUBY AND NOT DISABLE_LUA)
ADD_SUBDIRECTORY( scripts )
ENDIF(NOT DISABLE_PERL AND NOT DISABLE_PYTHON AND NOT DISABLE_RUBY AND NOT DISABLE_LUA)
IF(NOT DISABLE_ASPELL)
# Check for aspell libraries
FIND_PACKAGE(Aspell)
@ -51,10 +47,18 @@ IF(NOT DISABLE_FIFO)
ADD_SUBDIRECTORY( fifo )
ENDIF(NOT DISABLE_FIFO)
IF(NOT DISABLE_LOGGER)
ADD_SUBDIRECTORY( logger )
ENDIF(NOT DISABLE_LOGGER)
IF(NOT DISABLE_TRIGGER)
ADD_SUBDIRECTORY( trigger )
ENDIF(NOT DISABLE_TRIGGER)
IF(NOT DISABLE_PERL AND NOT DISABLE_PYTHON AND NOT DISABLE_RUBY AND NOT DISABLE_LUA)
ADD_SUBDIRECTORY( scripts )
ENDIF(NOT DISABLE_PERL AND NOT DISABLE_PYTHON AND NOT DISABLE_RUBY AND NOT DISABLE_LUA)
IF(ENABLE_DEMO)
ADD_SUBDIRECTORY( demo )
ENDIF(ENABLE_TRIGGER)

View File

@ -32,6 +32,26 @@ if PLUGIN_IRC
irc_dir = irc
endif
if PLUGIN_ASPELL
aspell_dir = aspell
endif
if PLUGIN_CHARSET
charset_dir = charset
endif
if PLUGIN_FIFO
fifo_dir = fifo
endif
if PLUGIN_LOGGER
logger_dir = logger
endif
if PLUGIN_TRIGGER
trigger_dir = trigger
endif
if PLUGIN_PERL
script_dir = scripts
endif
@ -48,24 +68,8 @@ if PLUGIN_LUA
script_dir = scripts
endif
if PLUGIN_ASPELL
aspell_dir = aspell
endif
if PLUGIN_CHARSET
charset_dir = charset
endif
if PLUGIN_FIFO
fifo_dir = fifo
endif
if PLUGIN_TRIGGER
trigger_dir = trigger
endif
if PLUGIN_DEMO
demo_dir = demo
endif
SUBDIRS = . $(irc_dir) $(script_dir) $(aspell_dir) $(charset_dir) $(fifo_dir) $(trigger_dir) $(demo_dir)
SUBDIRS = . $(irc_dir) $(aspell_dir) $(charset_dir) $(fifo_dir) $(logger_dir) $(trigger_dir) $(demo_dir) $(script_dir)

View File

@ -0,0 +1,22 @@
# Copyright (c) 2003-2007 FlashCode <flashcode@flashtux.org>
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
#
ADD_LIBRARY(logger MODULE logger.c logger.h logger-buffer.c logger-buffer.h)
SET_TARGET_PROPERTIES(logger PROPERTIES PREFIX "")
TARGET_LINK_LIBRARIES(logger)
INSTALL(TARGETS logger LIBRARY DESTINATION lib/${PROJECT_NAME}/plugins)

View File

@ -0,0 +1,25 @@
# Copyright (c) 2003-2007 FlashCode <flashcode@flashtux.org>
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
#
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(LOGGER_CFLAGS)
libdir = ${weechat_libdir}/plugins
lib_LTLIBRARIES = logger.la
logger_la_SOURCES = logger.c logger.h logger-buffer.c logger-buffer.h
logger_la_LDFLAGS = -module
logger_la_LIBADD = $(LOGGER_LFLAGS)

View File

@ -0,0 +1,143 @@
/*
* Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/* logger-buffer.c: manages logger buffer list */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "logger-buffer.h"
struct t_logger_buffer *logger_buffers = NULL;
struct t_logger_buffer *last_logger_buffer = NULL;
/*
* logger_buffer_add: add a new buffer for logging
*/
struct t_logger_buffer *
logger_buffer_add (void *buffer, char *log_filename)
{
struct t_logger_buffer *new_logger_buffer;
if (!buffer || !log_filename)
return NULL;
new_logger_buffer = (struct t_logger_buffer *)malloc (sizeof (struct t_logger_buffer));
if (new_logger_buffer)
{
new_logger_buffer->buffer = buffer;
new_logger_buffer->log_filename = strdup (log_filename);
new_logger_buffer->log_file = NULL;
new_logger_buffer->prev_buffer = last_logger_buffer;
new_logger_buffer->next_buffer = NULL;
if (logger_buffers)
last_logger_buffer->next_buffer = new_logger_buffer;
else
logger_buffers = new_logger_buffer;
last_logger_buffer = new_logger_buffer;
}
return new_logger_buffer;
}
/*
* logger_buffer_search: search a logger buffer by buffer pointer
*/
struct t_logger_buffer *
logger_buffer_search (void *buffer)
{
struct t_logger_buffer *ptr_logger_buffer;
for (ptr_logger_buffer = logger_buffers; ptr_logger_buffer;
ptr_logger_buffer = ptr_logger_buffer->next_buffer)
{
if (ptr_logger_buffer->buffer == (struct t_gui_buffer *)buffer)
return ptr_logger_buffer;
}
/* logger buffer not found */
return NULL;
}
/*
* logger_buffer_free: remove a logger buffer from list
*/
void
logger_buffer_free (struct t_logger_buffer *logger_buffer)
{
struct t_logger_buffer *new_logger_buffers;
/* remove logger buffer */
if (last_logger_buffer == logger_buffer)
last_logger_buffer = logger_buffer->prev_buffer;
if (logger_buffer->prev_buffer)
{
(logger_buffer->prev_buffer)->next_buffer = logger_buffer->next_buffer;
new_logger_buffers = logger_buffers;
}
else
new_logger_buffers = logger_buffer->next_buffer;
if (logger_buffer->next_buffer)
(logger_buffer->next_buffer)->prev_buffer = logger_buffer->prev_buffer;
/* free data */
if (logger_buffer->log_filename)
free (logger_buffer->log_filename);
logger_buffers = new_logger_buffers;
}
/*
* logger_buffer_remove: remove a buffer from list
*/
void
logger_buffer_remove (void *buffer)
{
struct t_logger_buffer *ptr_logger_buffer;
ptr_logger_buffer = logger_buffer_search (buffer);
if (ptr_logger_buffer)
logger_buffer_free (ptr_logger_buffer);
}
/*
* logger_buffer_remove_all: remove all buffers from list
*/
void
logger_buffer_remove_all ()
{
while (logger_buffers)
{
logger_buffer_free (logger_buffers);
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_LOGGER_BUFFER_H
#define __WEECHAT_LOGGER_BUFFER_H 1
struct t_logger_buffer
{
struct t_gui_buffer *buffer; /* pointer to buffer */
char *log_filename; /* log filename */
FILE *log_file; /* log file */
struct t_logger_buffer *prev_buffer; /* link to previous buffer */
struct t_logger_buffer *next_buffer; /* link to next buffer */
};
extern struct t_logger_buffer *logger_buffers;
extern struct t_logger_buffer *last_logger_buffer;
extern struct t_logger_buffer *logger_buffer_add (void *, char *);
extern struct t_logger_buffer *logger_buffer_search (void *);
extern void logger_buffer_remove (void *);
extern void logger_buffer_remove_all ();
#endif /* logger-buffer.h */

392
src/plugins/logger/logger.c Normal file
View File

@ -0,0 +1,392 @@
/*
* Copyright (c) 2003-2007 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/* logger.c: Logger plugin for WeeChat */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include "../weechat-plugin.h"
#include "logger.h"
#include "logger-buffer.h"
static struct t_weechat_plugin *weechat_plugin = NULL;
static char *logger_path = NULL;
static char *logger_time_format = NULL;
/*
* logger_config_read: read config options for logger plugin
*/
static void
logger_config_read ()
{
if (logger_path)
free (logger_path);
logger_path = weechat_plugin_config_get ("path");
if (!logger_path)
{
weechat_plugin_config_set ("path", "%h/logs/");
logger_path = weechat_plugin_config_get ("path");
}
if (logger_time_format)
free (logger_time_format);
logger_time_format = weechat_plugin_config_get ("time_format");
if (!logger_time_format)
{
weechat_plugin_config_set ("time_format", "%Y %b %d %H:%M:%S");
logger_time_format = weechat_plugin_config_get ("time_format");
}
}
/*
* logger_get_filename: build log filename for a buffer
*/
char *
logger_get_filename (void *buffer)
{
struct t_plugin_list *ptr_list;
char *res;
char *dir_separator, *weechat_dir, *log_path, *log_path2;
char *category, *category2, *name, *name2;
int length;
res = NULL;
dir_separator = weechat_info_get ("dir_separator");
weechat_dir = weechat_info_get ("weechat_dir");
log_path = weechat_string_replace (logger_path, "~", getenv ("HOME"));
log_path2 = weechat_string_replace (log_path, "%h", weechat_dir);
if (dir_separator && weechat_dir && log_path && log_path2)
{
ptr_list = weechat_list_get ("buffer", buffer);
if (ptr_list)
{
category2 = NULL;
name2 = NULL;
if (weechat_list_next (ptr_list))
{
category = weechat_list_string (ptr_list, "category");
category2 = (category) ?
weechat_string_replace (category, dir_separator, "_") : NULL;
name = weechat_list_string (ptr_list, "name");
name2 = (name) ?
weechat_string_replace (name, dir_separator, "_") : NULL;
}
length = strlen (log_path2);
if (category2)
length += strlen (category2);
if (name2)
length += strlen (name2);
length += 16;
res = (char *)malloc (length);
if (res)
{
strcpy (res, log_path2);
if (category2)
{
strcat (res, category2);
strcat (res, ".");
}
if (name2)
{
strcat (res, name2);
strcat (res, ".");
}
strcat (res, "weechatlog");
}
if (category2)
free (category2);
if (name2)
free (name2);
weechat_list_free (ptr_list);
}
}
if (dir_separator)
free (dir_separator);
if (weechat_dir)
free (weechat_dir);
if (log_path)
free (log_path);
if (log_path2)
free (log_path2);
return res;
}
/*
* logger_write_line: write a line to log file
*/
void
logger_write_line (struct t_logger_buffer *logger_buffer, char *format, ...)
{
va_list argptr;
char buf[4096], *charset, *message;
if (logger_buffer->log_file)
{
va_start (argptr, format);
vsnprintf (buf, sizeof (buf) - 1, format, argptr);
va_end (argptr);
charset = weechat_info_get ("charset_terminal");
message = (charset) ?
weechat_iconv_from_internal (charset, buf) : NULL;
fprintf (logger_buffer->log_file,
"%s\n", (message) ? message : buf);
fflush (logger_buffer->log_file);
if (charset)
free (charset);
if (message)
free (message);
}
}
/*
* logger_start_buffer: start a log for a buffer
*/
void
logger_start_buffer (void *buffer)
{
struct t_logger_buffer *ptr_logger_buffer;
char *log_filename;
time_t seconds;
struct tm *date_tmp;
char buf_time[256];
if (!buffer)
return;
ptr_logger_buffer = logger_buffer_search (buffer);
if (!ptr_logger_buffer)
{
log_filename = logger_get_filename (buffer);
if (!log_filename)
return;
ptr_logger_buffer = logger_buffer_add (buffer, log_filename);
free (log_filename);
}
if (ptr_logger_buffer)
{
if (ptr_logger_buffer->log_filename)
{
if (ptr_logger_buffer->log_file)
fclose (ptr_logger_buffer->log_file);
ptr_logger_buffer->log_file =
fopen (ptr_logger_buffer->log_filename, "a");
if (!ptr_logger_buffer->log_file)
{
weechat_printf (NULL,
_("%sLogger: unable to write log file \"%s\"\n"),
weechat_prefix ("error"),
ptr_logger_buffer->log_filename);
free (ptr_logger_buffer->log_filename);
return;
}
seconds = time (NULL);
date_tmp = localtime (&seconds);
buf_time[0] = '\0';
if (date_tmp)
strftime (buf_time, sizeof (buf_time) - 1,
logger_time_format, date_tmp);
logger_write_line (ptr_logger_buffer,
_("**** Beginning of log %s ****"),
buf_time);
}
}
}
/*
* logger_start_buffer_all: start log buffer for all buffers
*/
void
logger_start_buffer_all ()
{
struct t_plugin_list *ptr_list;
ptr_list = weechat_list_get ("buffer", NULL);
while (weechat_list_next (ptr_list))
{
logger_start_buffer (weechat_list_pointer (ptr_list, "pointer"));
}
}
/*
* logger_end: end log for a logger buffer
*/
void
logger_end (struct t_logger_buffer *logger_buffer)
{
time_t seconds;
struct tm *date_tmp;
char buf_time[256];
if (!logger_buffer)
return;
if (logger_buffer->log_file)
{
seconds = time (NULL);
date_tmp = localtime (&seconds);
buf_time[0] = '\0';
if (date_tmp)
strftime (buf_time, sizeof (buf_time) - 1,
logger_time_format, date_tmp);
logger_write_line (logger_buffer,
_("**** End of log %s ****"),
buf_time);
fclose (logger_buffer->log_file);
logger_buffer->log_file = NULL;
logger_buffer_remove (logger_buffer);
}
}
/*
* logger_end_all: end log for all buffers
*/
void
logger_end_all ()
{
struct t_logger_buffer *ptr_logger_buffer;
for (ptr_logger_buffer = logger_buffers; ptr_logger_buffer;
ptr_logger_buffer = ptr_logger_buffer->next_buffer)
{
logger_end (ptr_logger_buffer);
}
}
/*
* logger_event_cb: callback for event hook
*/
static int
logger_event_cb (void *data, char *event, void *pointer)
{
/* make C compiler happy */
(void) data;
(void) pointer;
if (weechat_strcasecmp (event, "buffer_open") == 0)
{
logger_start_buffer (pointer);
}
else if (weechat_strcasecmp (event, "buffer_close") == 0)
{
logger_end (logger_buffer_search (pointer));
}
return PLUGIN_RC_SUCCESS;
}
/*
* logger_print_cb: callback for print hook
*/
static int
logger_print_cb (void *data, void *buffer, time_t date, char *prefix,
char *message)
{
struct t_logger_buffer *ptr_logger_buffer;
struct tm *date_tmp;
char buf_time[256];
/* make C compiler happy */
(void) data;
ptr_logger_buffer = logger_buffer_search (buffer);
if (ptr_logger_buffer && ptr_logger_buffer->log_file)
{
date_tmp = localtime (&date);
buf_time[0] = '\0';
if (date_tmp)
strftime (buf_time, sizeof (buf_time) - 1,
logger_time_format, date_tmp);
logger_write_line (ptr_logger_buffer,
"%s%s%s%s%s",
buf_time,
(buf_time[0]) ? " " : "",
(prefix) ? prefix : "",
(prefix && prefix[0]) ? " " : "",
message);
}
return PLUGIN_RC_SUCCESS;
}
/*
* weechat_plugin_init: init logger plugin
*/
int
weechat_plugin_init (struct t_weechat_plugin *plugin)
{
weechat_plugin = plugin;
logger_config_read ();
if (!logger_path || !logger_time_format)
return PLUGIN_RC_FAILED;
logger_start_buffer_all ();
weechat_hook_event ("buffer_open", logger_event_cb, NULL);
weechat_hook_event ("buffer_close", logger_event_cb, NULL);
weechat_hook_print (NULL, NULL, 1, logger_print_cb, NULL);
return PLUGIN_RC_SUCCESS;
}
/*
* weechat_plugin_end: end logger plugin
*/
int
weechat_plugin_end ()
{
logger_end_all ();
return PLUGIN_RC_SUCCESS;
}

View File

@ -17,15 +17,11 @@
*/
#ifndef __WEECHAT_GUI_LOG_H
#define __WEECHAT_GUI_LOG_H 1
#ifndef __WEECHAT_LOGGER_H
#define __WEECHAT_LOGGER_H 1
/* log functions */
char plugin_name[] = "logger";
char plugin_version[] = "0.1";
char plugin_description[] = "Logger plugin for WeeChat";
extern void gui_log_write_date (struct t_gui_buffer *);
extern void gui_log_write_line (struct t_gui_buffer *, char *);
extern void gui_log_write (struct t_gui_buffer *, char *);
extern void gui_log_start (struct t_gui_buffer *);
extern void gui_log_end (struct t_gui_buffer *);
#endif /* gui-log.h */
#endif /* logger.h */

View File

@ -825,8 +825,6 @@ plugin_api_list_get_add_buffer (struct t_plugin_list *list,
return 0;
if (!plugin_list_new_var_int (ptr_item, "num_displayed", buffer->num_displayed))
return 0;
if (!plugin_list_new_var_string (ptr_item, "log_filename", buffer->log_filename))
return 0;
if (!plugin_list_new_var_string (ptr_item, "title", buffer->title))
return 0;
if (!plugin_list_new_var_int (ptr_item, "input", buffer->input))