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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * $Id: debug.c,v 1.5 2006/01/26 02:16:28 mclark Exp $
  3. *
  4. * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
  5. * Michael Clark <michael@metaparadigm.com>
  6. *
  7. * This library is free software; you can redistribute it and/or modify
  8. * it under the terms of the MIT license. See COPYING for details.
  9. *
  10. */
  11. #include "config.h"
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <stdarg.h>
  16. #if HAVE_SYSLOG_H
  17. # include <syslog.h>
  18. #endif /* HAVE_SYSLOG_H */
  19. #if HAVE_UNISTD_H
  20. # include <unistd.h>
  21. #endif /* HAVE_UNISTD_H */
  22. #if HAVE_SYS_PARAM_H
  23. #include <sys/param.h>
  24. #endif /* HAVE_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(void) { 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 HAVE_VSYSLOG
  39. if(_syslog) {
  40. vsyslog(LOG_ERR, msg, ap);
  41. } else
  42. #endif
  43. vprintf(msg, ap);
  44. va_end(ap);
  45. exit(1);
  46. }
  47. void mc_debug(const char *msg, ...)
  48. {
  49. va_list ap;
  50. if(_debug) {
  51. va_start(ap, msg);
  52. #if HAVE_VSYSLOG
  53. if(_syslog) {
  54. vsyslog(LOG_DEBUG, msg, ap);
  55. } else
  56. #endif
  57. vprintf(msg, ap);
  58. va_end(ap);
  59. }
  60. }
  61. void mc_error(const char *msg, ...)
  62. {
  63. va_list ap;
  64. va_start(ap, msg);
  65. #if HAVE_VSYSLOG
  66. if(_syslog) {
  67. vsyslog(LOG_ERR, msg, ap);
  68. } else
  69. #endif
  70. vfprintf(stderr, msg, ap);
  71. va_end(ap);
  72. }
  73. void mc_info(const char *msg, ...)
  74. {
  75. va_list ap;
  76. va_start(ap, msg);
  77. #if HAVE_VSYSLOG
  78. if(_syslog) {
  79. vsyslog(LOG_INFO, msg, ap);
  80. } else
  81. #endif
  82. vfprintf(stderr, msg, ap);
  83. va_end(ap);
  84. }