lib_syslog.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /****************************************************************************
  2. * libs/libc/syslog/lib_syslog.c
  3. *
  4. * Copyright (C) 2007-2009, 2011-2014, 2016, 2018 Gregory Nutt. All rights
  5. * reserved.
  6. * Author: Gregory Nutt <gnutt@nuttx.org>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * 3. Neither the name NuttX nor the names of its contributors may be
  19. * used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ****************************************************************************/
  36. /****************************************************************************
  37. * Included Files
  38. ****************************************************************************/
  39. #include <nuttx/config.h>
  40. #include <stdarg.h>
  41. #include <syslog.h>
  42. #include <nuttx/syslog/syslog.h>
  43. #include "syslog/syslog.h"
  44. /****************************************************************************
  45. * Public Functions
  46. ****************************************************************************/
  47. /****************************************************************************
  48. * Name: vsyslog
  49. *
  50. * Description:
  51. * The function vsyslog() performs the same task as syslog() with the
  52. * difference that it takes a set of arguments which have been obtained
  53. * using the stdarg variable argument list macros.
  54. *
  55. * Returned Value:
  56. * None.
  57. *
  58. ****************************************************************************/
  59. void vsyslog(int priority, FAR const IPTR char *fmt, va_list ap)
  60. {
  61. /* Check if this priority is enabled */
  62. if ((g_syslog_mask & LOG_MASK(priority)) != 0)
  63. {
  64. /* Yes.. Perform the nx_vsyslog system call.
  65. *
  66. * NOTE: The va_list parameter is passed by reference. That is
  67. * because the va_list is a structure in some compilers and passing
  68. * of structures in the NuttX syscalls does not work.
  69. */
  70. #ifdef va_copy
  71. va_list copy;
  72. va_copy(copy, ap);
  73. nx_vsyslog(priority, fmt, &copy);
  74. va_end(copy);
  75. #else
  76. nx_vsyslog(priority, fmt, &ap);
  77. #endif
  78. }
  79. }
  80. /****************************************************************************
  81. * Name: syslog
  82. *
  83. * Description:
  84. * syslog() generates a log message. The priority argument is formed by
  85. * ORing the facility and the level values (see include/syslog.h). The
  86. * remaining arguments are a format, as in printf and any arguments to the
  87. * format.
  88. *
  89. * The NuttX implementation does not support any special formatting
  90. * characters beyond those supported by printf.
  91. *
  92. * Returned Value:
  93. * None.
  94. *
  95. ****************************************************************************/
  96. void syslog(int priority, FAR const IPTR char *fmt, ...)
  97. {
  98. va_list ap;
  99. /* Let vsyslog do the work */
  100. va_start(ap, fmt);
  101. vsyslog(priority, fmt, ap);
  102. va_end(ap);
  103. }