debug.c
Go to the documentation of this file.
00001 /*
00002  * $Id: debug.c,v 1.5 2006/01/26 02:16:28 mclark Exp $
00003  *
00004  * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
00005  * Michael Clark <michael@metaparadigm.com>
00006  *
00007  * This library is free software; you can redistribute it and/or modify
00008  * it under the terms of the MIT license. See COPYING for details.
00009  *
00010  */
00011 
00012 #include "config.h"
00013 
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <string.h>
00017 #include <stdarg.h>
00018 
00019 #if HAVE_SYSLOG_H
00020 # include <syslog.h>
00021 #endif /* HAVE_SYSLOG_H */
00022 
00023 #if HAVE_UNISTD_H
00024 # include <unistd.h>
00025 #endif /* HAVE_UNISTD_H */
00026 
00027 #if HAVE_SYS_PARAM_H
00028 #include <sys/param.h>
00029 #endif /* HAVE_SYS_PARAM_H */
00030 
00031 #include "debug.h"
00032 
00033 static int _syslog = 0;
00034 static int _debug = 0;
00035 
00036 void mc_set_debug(int debug) { _debug = debug; }
00037 int mc_get_debug() { return _debug; }
00038 
00039 extern void mc_set_syslog(int syslog)
00040 {
00041   _syslog = syslog;
00042 }
00043 
00044 void mc_abort(const char *msg, ...)
00045 {
00046   va_list ap;
00047   va_start(ap, msg);
00048 #if HAVE_VSYSLOG
00049   if(_syslog) {
00050           vsyslog(LOG_ERR, msg, ap);
00051   } else
00052 #endif
00053           vprintf(msg, ap);
00054   exit(1);
00055 }
00056 
00057 
00058 void mc_debug(const char *msg, ...)
00059 {
00060   va_list ap;
00061   if(_debug) {
00062     va_start(ap, msg);
00063 #if HAVE_VSYSLOG
00064     if(_syslog) {
00065                 vsyslog(LOG_DEBUG, msg, ap);
00066         } else
00067 #endif
00068                 vprintf(msg, ap);
00069   }
00070 }
00071 
00072 void mc_error(const char *msg, ...)
00073 {
00074   va_list ap;
00075   va_start(ap, msg);
00076 #if HAVE_VSYSLOG
00077     if(_syslog) {
00078                 vsyslog(LOG_ERR, msg, ap);
00079         } else
00080 #endif
00081                 vfprintf(stderr, msg, ap);
00082 }
00083 
00084 void mc_info(const char *msg, ...)
00085 {
00086   va_list ap;
00087   va_start(ap, msg);
00088 #if HAVE_VSYSLOG
00089     if(_syslog) {
00090                 vsyslog(LOG_INFO, msg, ap);
00091         } else 
00092 #endif
00093                 vfprintf(stderr, msg, ap);
00094 }


csm
Author(s): Andrea Censi
autogenerated on Fri May 17 2019 02:28:33