Skip to content

Commit

Permalink
logAppend: include timestamp for messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Czigler committed Dec 18, 2020
1 parent 8206253 commit 20a7e3b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions kirc.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,25 @@ static void stateReset(struct State * l) {
l->buflen--;
}

static char * ctime_now(char buf[26]) {
struct tm tm_;
time_t now = time(NULL);
if (!asctime_r(localtime_r (&now, &tm_), buf))
return NULL;
*strchr(buf, '\n') = '\0';
return buf;
}

static void logAppend(char * str, char * path) {
FILE * out;
char buf[26];

if ((out = fopen(path, "a")) == NULL) {
perror("fopen");
exit(1);
}

fputs(str, out);
ctime_now(buf);
fprintf(out, "%s:%s", buf, str);
fclose(out);
}

Expand Down Expand Up @@ -489,15 +499,6 @@ static void paramPrintJoin(struct Param * p) {
printf(" [\x1b[33m%s\x1b[0m] ", p->channel);
}

static char * ctime_now (char buf[26]) {
struct tm tm_;
time_t now = time(NULL);
if (!asctime_r(localtime_r (&now, &tm_), buf))
return NULL;
*strchr(buf, '\n') = '\0';
return buf;
}

static void handleCTCP(const char * nickname, char * message) {
if (message[0] != '\001' && strncmp(message, "ACTION", 6))
return;
Expand Down

0 comments on commit 20a7e3b

Please sign in to comment.