/*
** LOG: Simple minded message logging interface
** Copyright (C) 2002 Michael W. Shaffer <mwshaffer@angrypot.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program (see the file COPYING). If not, write to:
**
** The Free Software Foundation, Inc.
** 59 Temple Place, Suite 330,
** Boston, MA 02111-1307 USA
*/
#include <stdlib.h>
#include "conf.h"
#include "log.h"
struct logger {
void (*init) (void);
void (*free) (void);
void (*set_level) (int level);
void (*msg) (int pri, char *msg);
};
static struct logger l = {
log_init_stderr,
log_free_stderr,
log_set_level_stderr,
log_msg_stderr,
};
void log_init (void)
{
char *mode = NULL;
mode = get_config_string ("log-mode");
if (mode && (!strcmp (mode, "file"))) {
l.init = log_init_file;
l.free = log_free_file;
l.msg = log_msg_file;
l.set_level = log_set_level_file;
} else if (mode && (!strcmp (mode, "syslog"))) {
l.init = log_init_syslog;
l.free = log_free_syslog;
l.msg = log_msg_syslog;
l.set_level = log_set_level_syslog;
}
if (l.init)
l.init ();
return;
}
void log_free (void)
{
if (l.free)
l.free ();
return;
}
void log_msg (int pri, char *msg)
{
if (l.msg)
l.msg (pri, msg);
return;
}
void log_set_level (int level)
{
if (l.set_level)
l.set_level (level);
return;
}
syntax highlighted by Code2HTML, v. 0.9.1