/*
 *  libmodem library, a modem control facility.
 *
 *  mdmlog.c - syslog facility for library debugging
 *
 *  Copyright (C) 1994, 1995  Riccardo Facchetti
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library 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
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  You can contact the author at this e-mail address:
 *
 *  riccardo@cdc8g5.cdc.polimi.it
 */

#if defined(DEBUG)
#include <stdio.h>
#include <stdarg.h>
#include <syslog.h>
#include <errno.h>

#include <dial/modems.h>

static int log_opened = 0;

void mdm_log(int logid, char *fmt, ...) {
va_list args;
char buffer[1024];

va_start(args, fmt);

vsprintf(buffer, fmt, args);

va_end(args);

syslog(logid, buffer);

if (logid == LOG_ERR)
    fprintf(stderr, "%s (%s)\n", buffer, strerror(errno));
}

void open_mdm_log (void) {
    if (!log_opened) {
        openlog ("libmodem "LIBMODEM_VER, LOG_PID|LOG_CONS|LOG_NOWAIT, LOG_LOCAL1);
        log_opened = 1;
    }
}

void close_mdm_log (void) {
    if (log_opened) {
        closelog();
        log_opened = 0;
    }
}

#endif /* DEBUG */
