2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * journal.c: Log a journal of events to a file
30 * Known contributors to this file:
31 * Markus Armbruster, 2004-2008
32 * Ron Koenderink, 2008
36 * Journal file format: each line logs an event, and looks like this:
38 * TIME THREAD EVENT DATA
40 * Events and their data are:
45 * login CNUM HOSTADDR USER
60 #include "empthread.h"
64 #include "prototypes.h"
66 static char journal_fname[] = "journal.log";
69 static void journal_entry(char *fmt, ...)
70 ATTRIBUTE((format (printf, 1, 2)));
75 return fopen(journal_fname, "a+");
79 journal_entry(char *fmt, ...)
81 static char buf[1024];
88 fprintf(journal, "%.24s %10.10s ",
89 ctime(&now), empth_name(empth_self()));
92 vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
95 for (p = (unsigned char *)buf; *p; p++) {
99 fprintf(journal, "\\%03o", *p);
101 fputs("\n", journal);
103 if (ferror(journal)) {
104 logerror("Error writing journal (%s)", strerror(errno));
111 journal_startup(void)
115 journal = journal_open();
117 logerror("Can't open %s (%s)", journal_fname, strerror(errno));
120 journal_entry("startup");
125 journal_shutdown(void)
127 journal_entry("shutdown");
143 logerror("Can't open %s (%s)", journal_fname, strerror(errno));
153 journal_prng(unsigned seed)
155 journal_entry("prng BSD %d", seed);
161 journal_entry("login %d %s %s",
162 player->cnum, player->hostaddr, player->userid);
168 journal_entry("logout %d", player->cnum);
172 journal_input(char *input)
174 journal_entry("input %s", input);
178 journal_command(char *cmd)
180 char *eptr = strchr(cmd, ' ');
181 journal_entry("command %.*s", eptr ? (int)(eptr - cmd) : -1, cmd);
185 journal_update(int etu)
187 journal_entry("update %d", etu);