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.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <stdarg.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.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)
  29. {
  30. _debug = debug;
  31. }
  32. int mc_get_debug(void)
  33. {
  34. return _debug;
  35. }
  36. extern void mc_set_syslog(int syslog)
  37. {
  38. _syslog = syslog;
  39. }
  40. void mc_debug(const char *msg, ...)
  41. {
  42. va_list ap;
  43. if (_debug)
  44. {
  45. va_start(ap, msg);
  46. #if HAVE_VSYSLOG
  47. if (_syslog)
  48. {
  49. vsyslog(LOG_DEBUG, msg, ap);
  50. }
  51. else
  52. #endif
  53. vprintf(msg, ap);
  54. va_end(ap);
  55. }
  56. }
  57. void mc_error(const char *msg, ...)
  58. {
  59. va_list ap;
  60. va_start(ap, msg);
  61. #if HAVE_VSYSLOG
  62. if (_syslog)
  63. {
  64. vsyslog(LOG_ERR, msg, ap);
  65. }
  66. else
  67. #endif
  68. vfprintf(stderr, msg, ap);
  69. va_end(ap);
  70. }
  71. void mc_info(const char *msg, ...)
  72. {
  73. va_list ap;
  74. va_start(ap, msg);
  75. #if HAVE_VSYSLOG
  76. if (_syslog)
  77. {
  78. vsyslog(LOG_INFO, msg, ap);
  79. }
  80. else
  81. #endif
  82. vfprintf(stderr, msg, ap);
  83. va_end(ap);
  84. }