1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-07 10:13:12 +02:00

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
+2 -3
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})
-2
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 \
-32
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);
-4
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 */
-150
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;
}
}
-31
View File
@@ -1,31 +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/>.
*/
#ifndef __WEECHAT_GUI_LOG_H
#define __WEECHAT_GUI_LOG_H 1
/* log functions */
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 */