[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[patch] new logfile for each day if date is used in log filename mask
Hi,
attached a patch that creates a new logfile for each calendar day if the %y
(date) placeholder is used in the logfile mask. I have added a new option for
this.
Cheers
-Tim
? Makefile.in
? xchat.dailylogs.diff
? xchat.diff
? xchat2-beepcmd.diff
? common/Makefile.in
? fe-gtk/Makefile.in
? fe-text/Makefile.in
? pixmaps/Makefile.in
Index: common/cfgfiles.c
===================================================================
RCS file: /cvsroot/xchat/xchat2/src/common/cfgfiles.c,v
retrieving revision 1.41
diff -u -r1.41 cfgfiles.c
--- common/cfgfiles.c 21 Sep 2003 12:17:30 -0000 1.41
+++ common/cfgfiles.c 14 Oct 2003 19:41:59 -0000
@@ -430,6 +430,7 @@
{"irc_hide_version", P_OFFINT (hidever), TYPE_BOOL},
{"irc_invisible", P_OFFINT (invisible), TYPE_BOOL},
{"irc_logging", P_OFFINT (logging), TYPE_BOOL},
+ {"irc_dailylogs", P_OFFINT(dailylogs), TYPE_BOOL},
{"irc_logmask", P_OFFSET (logmask), TYPE_STR},
{"irc_nick1", P_OFFSET (nick1), TYPE_STR},
{"irc_nick2", P_OFFSET (nick2), TYPE_STR},
Index: common/text.c
===================================================================
RCS file: /cvsroot/xchat/xchat2/src/common/text.c,v
retrieving revision 1.35
diff -u -r1.35 text.c
--- common/text.c 7 Oct 2003 05:06:51 -0000 1.35
+++ common/text.c 14 Oct 2003 19:42:00 -0000
@@ -430,6 +430,8 @@
sess->logfd = log_open_file (sess->server->servername, sess->channel,
sess->server->networkname);
+ sess->lastlog = time (0);
+
if (!log_error && sess->logfd == -1)
{
char message[512];
@@ -463,15 +465,38 @@
static void
log_write (session *sess, char *text)
{
+ time_t now;
char *temp;
char *stamp;
int len;
+ now = time(0);
+
+ /* date string in log file name? */
+ if (prefs.dailylogs && strstr(prefs.logmask, "%y"))
+ {
+ struct tm *tmnow, *tmlastlog;
+ int ydaynow;
+
+ tmnow = localtime(&now);
+ ydaynow = tmnow->tm_yday;
+
+ tmlastlog = localtime(&(sess->lastlog));
+
+ /* Is it a new day? If yes, create
+ * new logfile with new date in filename */
+ if (ydaynow != tmlastlog->tm_yday)
+ {
+ log_open (sess); /* will also close current log */
+ }
+ }
+
+
if (sess->logfd != -1 && prefs.logging)
{
if (prefs.timestamp_logs)
{
- len = get_stamp_str (prefs.timestamp_log_format, time (0), &stamp);
+ len = get_stamp_str (prefs.timestamp_log_format, now, &stamp);
if (len)
{
write (sess->logfd, stamp, len);
@@ -481,6 +506,7 @@
temp = strip_color (text);
write (sess->logfd, temp, strlen (temp));
free (temp);
+ sess->lastlog = now;
}
}
Index: common/xchat.h
===================================================================
RCS file: /cvsroot/xchat/xchat2/src/common/xchat.h,v
retrieving revision 1.24
diff -u -r1.24 xchat.h
--- common/xchat.h 23 Jul 2003 09:16:41 -0000 1.24
+++ common/xchat.h 14 Oct 2003 19:42:01 -0000
@@ -214,6 +214,7 @@
unsigned int truncchans;
unsigned int privmsgtab;
unsigned int logging;
+ unsigned int dailylogs;
unsigned int timestamp_logs;
unsigned int newtabstofront;
unsigned int dccwithnick;
@@ -277,6 +278,7 @@
char channelkey[64]; /* XXX correct max length? */
int limit; /* channel user limit */
int logfd;
+ time_t lastlog; /* if %y is in logmask, we want to close logfile at midnight and re-open with new dated filename */
char lastnick[NICKLEN]; /* last nick you /msg'ed */
Index: fe-gtk/setup.c
===================================================================
RCS file: /cvsroot/xchat/xchat2/src/fe-gtk/setup.c,v
retrieving revision 1.28
diff -u -r1.28 setup.c
--- fe-gtk/setup.c 14 Oct 2003 05:54:08 -0000 1.28
+++ fe-gtk/setup.c 14 Oct 2003 19:42:02 -0000
@@ -224,11 +224,12 @@
static const setting logging_settings[] =
{
{ST_ENTRY, N_("Log filename mask:"), P_OFFSET(logmask), 0, 0, sizeof prefs.logmask},
- {ST_LABEL, N_("(%s=Server %c=Channel %n=Network).")},
+ {ST_LABEL, N_("(%s=Server %c=Channel %n=Network, %y=Date).")},
{ST_ENTRY, N_("Log timestamp format:"), P_OFFSET(timestamp_log_format), 0, 0, sizeof prefs.timestamp_log_format},
{ST_LABEL, N_("(See strftime manpage for details).")},
{ST_TOGGLE, N_("Enable logging of conversations"), P_OFFINT(logging), 0, 0, 0},
{ST_TOGGLE, N_("Insert timestamps in logs"), P_OFFINT(timestamp_logs), 0, 0, 0},
+ {ST_TOGGLE, N_("Separate logfiles for each day if %y is in logfile mask)"), P_OFFINT(dailylogs), 0, 0, 0},
{ST_END, 0, 0, 0, 0, 0}
};