2 * log.c -- logging functions for browser-switchboard
4 * Copyright (C) 2010 Steven Luo
5 * Derived from a Python implementation by Jason Simpson and Steven Luo
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
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 Street, Fifth Floor, Boston, MA 02110-1301,
30 #define DEFAULT_LOGGER LOGTO_STDOUT
35 } logger = DEFAULT_LOGGER;
37 /* Configure the logging target, performing any required setup for that
39 void log_config(char *logger_name) {
41 /* No logger configured, use the default log target */
42 logger = DEFAULT_LOGGER;
46 if (!strcmp(logger_name, "stdout"))
47 logger = LOGTO_STDOUT;
48 else if (!strcmp(logger_name, "syslog")) {
49 /* XXX allow syslog facility to be configured? */
50 openlog("browser-switchboard", LOG_PID, LOG_USER);
51 logger = LOGTO_SYSLOG;
53 else if (!strcmp(logger_name, "none"))
56 /* Invalid logger configured, use the default log target */
57 logger = DEFAULT_LOGGER;
62 /* Log output to the chosen log target */
63 void log_msg(const char *format, ...) {
74 /* XXX allow syslog priority to be set by caller? */
75 vsyslog(LOG_DEBUG, format, ap);
85 /* Log strerror(errnum), with the string in prefix appended
86 Behaves like perror() except that it logs to chosen target, not stderr */
87 void log_perror(int errnum, const char *prefix) {
92 if (!(errmsg = strerror(errnum)))
95 log_msg("%s: %s\n", prefix, errmsg);