You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

debug.c 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * $Id: debug.c,v 1.3 2004/08/07 03:11:38 mclark Exp $
  3. *
  4. * Copyright Metaparadigm Pte. Ltd. 2004.
  5. * Michael Clark <michael@metaparadigm.com>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public (LGPL)
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library 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 GNU
  15. * Lesser General Public License for more details: http://www.gnu.org/
  16. *
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <stdarg.h>
  22. #include <syslog.h>
  23. #include <unistd.h>
  24. #include <sys/param.h>
  25. #include "debug.h"
  26. static int _syslog = 0;
  27. static int _debug = 0;
  28. void mc_set_debug(int debug) { _debug = debug; }
  29. int mc_get_debug() { return _debug; }
  30. extern void mc_set_syslog(int syslog)
  31. {
  32. _syslog = syslog;
  33. }
  34. void mc_abort(const char *msg, ...)
  35. {
  36. va_list ap;
  37. va_start(ap, msg);
  38. if(_syslog) vsyslog(LOG_ERR, msg, ap);
  39. else vprintf(msg, ap);
  40. exit(1);
  41. }
  42. void mc_debug(const char *msg, ...)
  43. {
  44. va_list ap;
  45. if(_debug) {
  46. va_start(ap, msg);
  47. if(_syslog) vsyslog(LOG_DEBUG, msg, ap);
  48. else vprintf(msg, ap);
  49. }
  50. }
  51. void mc_error(const char *msg, ...)
  52. {
  53. va_list ap;
  54. va_start(ap, msg);
  55. if(_syslog) vsyslog(LOG_ERR, msg, ap);
  56. else vfprintf(stderr, msg, ap);
  57. }
  58. void mc_info(const char *msg, ...)
  59. {
  60. va_list ap;
  61. va_start(ap, msg);
  62. if(_syslog) vsyslog(LOG_INFO, msg, ap);
  63. else vfprintf(stderr, msg, ap);
  64. }

No Description

Contributors (1)