Permalink
Browse files

Logging

  • Loading branch information...
1 parent 06e5640 commit 8c8b00d36641cbd9867de36c35f7e153c3e6b6f9 ec429 committed Jun 14, 2012
Showing with 381 additions and 51 deletions.
  1. +7 −5 Makefile
  2. +13 −3 buffer.c
  3. +3 −37 buffer.h
  4. +7 −5 distMakefile
  5. +62 −0 input.c
  6. +157 −0 logging.c
  7. +9 −0 logging.h
  8. +3 −1 plans
  9. +65 −0 types.c
  10. +55 −0 types.h
View
@@ -8,8 +8,8 @@ VERSION := `git describe --tags`
PREFIX := /usr/local
# -lanl is for ASYNCH_NL
OPTLIBS := -lanl
-LIBS := -lncurses ttyraw.o ttyesc.o irc.o bits.o colour.o buffer.o names.o config.o input.o $(OPTLIBS)
-INCLUDE := ttyraw.h ttyesc.h irc.h bits.h colour.h buffer.h names.h config.h input.h quirc.h version.h osconf.h
+LIBS := -lncurses ttyraw.o ttyesc.o irc.o bits.o colour.o buffer.o names.o config.o input.o logging.o types.o $(OPTLIBS)
+INCLUDE := ttyraw.h ttyesc.h irc.h bits.h colour.h buffer.h names.h config.h input.h logging.h types.h quirc.h version.h osconf.h
all: quirc doc
@@ -68,9 +68,9 @@ bits.h: config.h
colour.o: colour.c colour.h c_init.c ttyesc.h
-buffer.o: buffer.c buffer.h ttyesc.h colour.h bits.h names.h text.h irc.h version.h input.h
+buffer.o: buffer.c buffer.h ttyesc.h colour.h bits.h names.h text.h irc.h version.h input.h logging.h
-buffer.h: config.h version.h
+buffer.h: config.h version.h logging.h
touch buffer.h
config.o: config.c config.h names.h bits.h colour.h text.h version.h
@@ -89,11 +89,13 @@ genconfig: genconfig.c
input.h: keymod.h
touch input.h
-input.o: input.c input.h ttyesc.h names.h buffer.h irc.h bits.h config.h
+input.o: input.c input.h ttyesc.h names.h buffer.h irc.h bits.h config.h logging.h
input.c: config_set.c
touch input.c
+logging.o: types.h bits.h
+
names.o: names.c names.h buffer.h irc.h
script.o: script.c script.h bits.h buffer.h
View
@@ -7,6 +7,7 @@
*/
#include "buffer.h"
+#include "logging.h"
int init_ring(ring *r)
{
@@ -117,6 +118,7 @@ int init_buffer(int buf, btype type, const char *bname, int nlines)
bufs[buf].server=0;
bufs[buf].nick=NULL;
bufs[buf].topic=NULL;
+ bufs[buf].logf=NULL;
bufs[buf].nlines=nlines;
bufs[buf].ptr=0;
bufs[buf].scroll=0;
@@ -190,11 +192,14 @@ int free_buffer(int buf)
bufs[buf].nlist=NULL;
n_free(bufs[buf].ilist);
bufs[buf].ilist=NULL;
+ free(bufs[buf].nick);
+ free(bufs[buf].topic);
+ if(bufs[buf].logf)
+ fclose(bufs[buf].logf);
free(bufs[buf].lm);
free(bufs[buf].lq);
free(bufs[buf].lp);
free(bufs[buf].ls);
- free(bufs[buf].topic);
int l;
if(bufs[buf].lt)
{
@@ -288,7 +293,7 @@ int add_to_buffer(int buf, mtype lm, prio lq, char lp, bool ls, const char *lt,
bufs[buf].lt[bufs[buf].ptr]=strdup(lt);
free(bufs[buf].ltag[bufs[buf].ptr]);
bufs[buf].ltag[bufs[buf].ptr]=strdup(ltag);
- bufs[buf].ts[bufs[buf].ptr]=time(NULL);
+ time_t ts=bufs[buf].ts[bufs[buf].ptr]=time(NULL);
bufs[buf].ptr=(bufs[buf].ptr+1)%bufs[buf].nlines;
if(scrollisptr)
{
@@ -314,6 +319,11 @@ int add_to_buffer(int buf, mtype lm, prio lq, char lp, bool ls, const char *lt,
))
bufs[buf].alert=true;
}
+ if(bufs[buf].logf)
+ {
+ int e=log_add(bufs[buf].logf, bufs[buf].logt, lm, lq, lp, ls, lt, ltag, ts);
+ if(e) return(e);
+ }
return(0);
}
@@ -529,7 +539,7 @@ int render_line(int buf, int uline)
strftime(stamp, 40, "[%a. %H:%M:%S %z] ", td);
break;
case 6:
- snprintf(stamp, 40, "[u+%lu] ", (unsigned long)bufs[buf].ts[uline]);
+ snprintf(stamp, 40, "[u+%lld] ", (signed long long)bufs[buf].ts[uline]);
break;
case 0: // no timestamps
default:
View
@@ -25,47 +25,11 @@
#include "irc.h"
#include "names.h"
#include "text.h"
+#include "types.h"
#include "version.h"
#define LIVE(buf) (bufs[buf].live && bufs[bufs[buf].server].live) // Check liveness
-typedef enum
-{
- STATUS,
- SERVER,
- CHANNEL,
- PRIVATE // right now we don't have handy private chat, you just have to /msg in a server or channel
-}
-btype;
-
-typedef enum
-{
- MSG,
- NOTICE,
- PREFORMAT,
- ACT,
- JOIN,
- PART,
- QUIT,
- QUIT_PREFORMAT,
- NICK,
- MODE,
- STA,
- ERR,
- UNK,
- UNK_NOTICE,
- UNN,
-}
-mtype;
-
-typedef enum
-{
- QUIET, // hide in quiet mode
- NORMAL, // always show
- DEBUG, // show only in debug mode
-}
-prio;
-
typedef struct _buf
{
btype type;
@@ -79,6 +43,8 @@ typedef struct _buf
int server; // used by CHANNELs and PRIVATE to denote their 'parent' server. In SERVER||STATUS, points to self. Is an offset into 'bufs'
char *nick; // used for SERVER: user's nick on this server
char *topic; // used for CHANNELs
+ FILE *logf;
+ logtype logt;
int nlines; // number of lines allocated
int ptr; // pointer to current unproc line
int scroll; // unproc line of screen bottom (which is one physical line below the last displayed text)
View
@@ -7,8 +7,8 @@ AWK ?= gawk
PREFIX ?= /usr/local
# -lanl is for ASYNCH_NL
OPTLIBS := -lanl
-LIBS := -lncurses ttyraw.o ttyesc.o irc.o bits.o colour.o buffer.o names.o config.o input.o $(OPTLIBS)
-INCLUDE := ttyraw.h ttyesc.h irc.h bits.h colour.h buffer.h names.h config.h input.h quirc.h version.h osconf.h
+LIBS := -lncurses ttyraw.o ttyesc.o irc.o bits.o colour.o buffer.o names.o config.o input.o logging.o types.o $(OPTLIBS)
+INCLUDE := ttyraw.h ttyesc.h irc.h bits.h colour.h buffer.h names.h config.h input.h logging.h types.h quirc.h version.h osconf.h
all: quirc doc
@@ -67,9 +67,9 @@ bits.h: config.h
colour.o: colour.c colour.h c_init.c ttyesc.h
-buffer.o: buffer.c buffer.h ttyesc.h colour.h bits.h names.h text.h irc.h version.h input.h
+buffer.o: buffer.c buffer.h ttyesc.h colour.h bits.h names.h text.h irc.h version.h input.h logging.h
-buffer.h: config.h version.h
+buffer.h: config.h version.h types.h
touch buffer.h
config.o: config.c config.h names.h bits.h colour.h text.h version.h
@@ -88,11 +88,13 @@ genconfig: genconfig.c
input.h: keymod.h
touch input.h
-input.o: input.c input.h ttyesc.h names.h buffer.h irc.h bits.h config.h
+input.o: input.c input.h ttyesc.h names.h buffer.h irc.h bits.h config.h logging.h
input.c: config_set.c
touch input.c
+logging.o: types.h bits.h
+
names.o: names.c names.h buffer.h irc.h
script.o: script.c script.h bits.h buffer.h
View
62 input.c
@@ -7,6 +7,7 @@
*/
#include "input.h"
+#include "logging.h"
int inputchar(iline *inp, int *state)
{
@@ -565,6 +566,67 @@ int cmd_handle(char *inp, char **qmsg, fd_set *master, int *fdmax) // old state=
add_to_buffer(cbuf, STA, NORMAL, 0, false, "Exited quirc", "/quit: ");
return(-1);
}
+ if(strcmp(cmd, "log")==0) // start/stop logging
+ {
+ if(!args)
+ {
+ add_to_buffer(cbuf, ERR, NORMAL, 0, false, "Must specify a log type or /log -", "/log: ");
+ return(0);
+ }
+ if(bufs[cbuf].logf)
+ {
+ fclose(bufs[cbuf].logf);
+ bufs[cbuf].logf=NULL;
+ }
+ if(strcmp(args, "-")==0)
+ {
+ add_to_buffer(cbuf, STA, QUIET, 0, false, "Disabled logging of this buffer", "/log: ");
+ return(0);
+ }
+ else
+ {
+ char *type=strtok(args, " ");
+ if(type)
+ {
+ char *fn=strtok(NULL, "");
+ if(fn)
+ {
+ logtype logt;
+ if(strcasecmp(type, "plain")==0)
+ logt=LOGT_PLAIN;
+ else if(strcasecmp(type, "symbolic")==0)
+ logt=LOGT_SYMBOLIC;
+ else
+ {
+ add_to_buffer(cbuf, ERR, NORMAL, 0, false, "Unrecognised log type (valid types are: plain, symbolic)", "/log: ");
+ return(0);
+ }
+ FILE *fp=fopen(fn, "a");
+ if(!fp)
+ {
+ add_to_buffer(cbuf, ERR, NORMAL, 0, false, "Failed to open log file for append", "/log: ");
+ add_to_buffer(cbuf, ERR, NORMAL, 0, false, strerror(errno), "fopen: ");
+ return(0);
+ }
+ log_init(fp, logt);
+ bufs[cbuf].logf=fp;
+ bufs[cbuf].logt=logt;
+ add_to_buffer(cbuf, STA, QUIET, 0, false, "Enabled logging of this buffer", "/log: ");
+ return(0);
+ }
+ else
+ {
+ add_to_buffer(cbuf, ERR, NORMAL, 0, false, "Must specify a log file", "/log: ");
+ return(0);
+ }
+ }
+ else
+ {
+ add_to_buffer(cbuf, ERR, NORMAL, 0, false, "Must specify a log type or /log -", "/log: ");
+ return(0);
+ }
+ }
+ }
if(strcmp(cmd, "set")==0) // set options
{
bool osp=show_prefix, odbg=debug, oind=indent;
Oops, something went wrong.

0 comments on commit 8c8b00d

Please sign in to comment.