syslog_P.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (C) 2004 by egnite Software GmbH. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the copyright holders nor the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  21. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  24. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  25. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  27. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. * For additional information see http://www.ethernut.de/
  31. *
  32. * -
  33. * Portions Copyright (c) 1983, 1988, 1993
  34. * The Regents of the University of California. All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. * 1. Redistributions of source code must retain the above copyright
  40. * notice, this list of conditions and the following disclaimer.
  41. * 2. Redistributions in binary form must reproduce the above copyright
  42. * notice, this list of conditions and the following disclaimer in the
  43. * documentation and/or other materials provided with the distribution.
  44. * 3. Neither the name of the University nor the names of its contributors
  45. * may be used to endorse or promote products derived from this software
  46. * without specific prior written permission.
  47. *
  48. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  49. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  52. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  53. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  54. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  56. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  57. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  58. * SUCH DAMAGE.
  59. */
  60. /*!
  61. * \file pro/syslog_P.c
  62. * \brief Syslog client routines for Harvard architecture
  63. *
  64. * \verbatim
  65. * $Id$
  66. * \endverbatim
  67. */
  68. #include <cfg/syslog.h>
  69. #include <stdio.h>
  70. #include <stdarg.h>
  71. #include <memdebug.h>
  72. #define SYSLOG_INTERNAL
  73. #include <sys/syslog.h>
  74. /*!
  75. * \addtogroup xgSyslog
  76. */
  77. /*@{*/
  78. #ifdef __HARVARD_ARCH__
  79. /*!
  80. * \brief Print log message.
  81. *
  82. * Alternate form of syslog(), in which the arguments have already been captured
  83. * using the variable-length argument facilities.
  84. *
  85. * This variant is useful for Harvard architectures only. It allows
  86. * to place the format string in program space. For other CPUs it
  87. * is mapped to vsyslog().
  88. *
  89. * \param pri Priority level of this message. See syslog().
  90. * \param fmt_P Format string containing conversion specifications like printf.
  91. * \param ap List of arguments.
  92. */
  93. void vsyslog_P(int pri, PGM_P fmt_P, va_list ap)
  94. {
  95. /* Build the header. */
  96. size_t cnt = syslog_header(pri);
  97. if (cnt) {
  98. #ifdef SYSLOG_PERROR_ONLY
  99. fputs(syslog_buf, stderr);
  100. vfprintf_P(stderr, fmt_P, ap);
  101. fputc('\n', stderr);
  102. #else
  103. cnt += vsnprintf_P(&syslog_buf[cnt], SYSLOG_MAXBUF - cnt, fmt_P, ap);
  104. syslog_flush(cnt);
  105. #endif /* SYSLOG_PERROR_ONLY */
  106. }
  107. }
  108. /*!
  109. * \brief Print log message.
  110. *
  111. * The message is tagged with priority.
  112. *
  113. * This variant is useful for Harvard architectures only. It allows
  114. * to place the format string in program space. For other CPUs it
  115. * is mapped to syslog().
  116. *
  117. * \param pri Priority level of this message, selected from the following
  118. * ordered list (high to low):
  119. * - LOG_EMERG A panic condition.
  120. * - LOG_ALERT A condition that should be corrected immediately.
  121. * - LOG_CRIT Critical conditions, e.g., hard device errors.
  122. * - LOG_ERR Errors.
  123. * - LOG_WARNING Warning messages.
  124. * - LOG_NOTICE Conditions that are not error conditions, but should
  125. * possibly be handled specially.
  126. * - LOG_INFO Informational messages.
  127. * - LOG_DEBUG Messages that contain information normally of use only
  128. * when debugging a program.
  129. * \param fmt_P Format string containing conversion specifications like printf.
  130. */
  131. void syslog_P(int pri, PGM_P fmt_P, ...)
  132. {
  133. va_list ap;
  134. va_start(ap, fmt_P);
  135. vsyslog_P(pri, fmt_P, ap);
  136. va_end(ap);
  137. }
  138. #endif /* __HARVARD_ARCH__ */
  139. /*@}*/