1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * This file is part of monster
6 * Copyright (C) 2006,2007 Nedko Arnaudov <nedko@arnaudov.name>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *****************************************************************************/
30 #define FORMATTING_BUFFER_SIZE 4096
32 void logwrite_file(const char * message
)
36 f
= fopen("/var/log/monster.log", "a");
40 /* we need cr because we use curses library */
41 fprintf(stderr
, "\rfailed to open/create /var/log/monster.log. error %d (%s)\r\n", errno
, strerror(errno
));
45 fwrite(message
, strlen(message
), 1, f
);
46 fwrite("\n", 1, 1, f
);
51 void logwrite_stderr(const char * message
)
53 fwrite("\r", 1, 1, stderr
);
54 fwrite(message
, strlen(message
), 1, stderr
);
55 fwrite("\r\n", 2, 1, stderr
); /* we need cr because we use curses library */
58 void logwrite_va(int lvl
, const char * format
, va_list arglist
)
60 char buffer
[FORMATTING_BUFFER_SIZE
];
62 vsnprintf(buffer
, FORMATTING_BUFFER_SIZE
-1, format
, arglist
);
66 logwrite_stderr(buffer
);
69 logwrite_file(buffer
);
72 void logwrite(int lvl
, const char * format
, ...)
76 va_start(arglist
, format
);
77 logwrite_va(lvl
, format
, arglist
);