syslog.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /****************************************************************************
  2. * include/nuttx/syslog/syslog.h
  3. * The NuttX SYSLOGing interface
  4. *
  5. * Copyright (C) 2012, 2014-2016 Gregory Nutt. All rights 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. #ifndef __INCLUDE_NUTTX_SYSLOG_SYSLOG_H
  37. #define __INCLUDE_NUTTX_SYSLOG_SYSLOG_H
  38. /****************************************************************************
  39. * Included Files
  40. ****************************************************************************/
  41. #include <nuttx/config.h>
  42. #include <nuttx/compiler.h>
  43. #include <sys/types.h>
  44. #include <stdarg.h>
  45. /****************************************************************************
  46. * Pre-processor Definitions
  47. ****************************************************************************/
  48. /* Configuration ************************************************************/
  49. /* CONFIG_SYSLOG_INTBUFFER - Enables an interrupt buffer that will be used
  50. * to serialize debug output from interrupt handlers.
  51. * CONFIG_SYSLOG_INTBUFSIZE - The size of the interrupt buffer in bytes.
  52. * CONFIG_SYSLOG_DEVPATH - The full path to the system logging device
  53. *
  54. * In addition, some SYSLOG device must also be enabled that will provide
  55. * the syslog output channel. As of this writing, there are two SYSLOG
  56. * devices available:
  57. *
  58. * 1. A RAM SYSLOGing device that will log data into a circular buffer
  59. * that can be dumped using the NSH dmesg command. This device is
  60. * described in the include/nuttx/syslog/ramlog.h header file.
  61. *
  62. * 2. And a generic character device that may be used as the SYSLOG. The
  63. * generic device interfaces are described in this file. A disadvantage
  64. * of using the generic character device for the SYSLOG is that it
  65. * cannot handle debug output generated from interrupt level handlers.
  66. *
  67. * CONFIG_SYSLOG_CHAR - Enable the generic character device for the SYSLOG.
  68. * The full path to the SYSLOG device is provided by CONFIG_SYSLOG_DEVPATH.
  69. * A valid character device must exist at this path. It will by opened
  70. * by logic in syslog_initialize() based on the current configuration.
  71. *
  72. * NOTE: No more than one SYSLOG device should be configured.
  73. */
  74. #if defined(CONFIG_SYSLOG_CHAR) && !defined(CONFIG_SYSLOG_DEVPATH)
  75. # define CONFIG_SYSLOG_DEVPATH "/dev/ttyS1"
  76. #endif
  77. #ifdef CONFIG_SYSLOG_INTBUFFER
  78. # ifndef CONFIG_SYSLOG_INTBUFSIZE
  79. # define CONFIG_SYSLOG_INTBUFSIZE 512
  80. # endif
  81. # if CONFIG_SYSLOG_INTBUFSIZE > 65535
  82. # undef CONFIG_SYSLOG_INTBUFSIZE
  83. # define CONFIG_SYSLOG_INTBUFSIZE 65535
  84. # endif
  85. #endif
  86. /****************************************************************************
  87. * Public Types
  88. ****************************************************************************/
  89. /* This structure provides the interface to a SYSLOG device */
  90. typedef CODE ssize_t (*syslog_write_t)(FAR const char *buf, size_t buflen);
  91. typedef CODE int (*syslog_putc_t)(int ch);
  92. typedef CODE int (*syslog_flush_t)(void);
  93. struct syslog_channel_s
  94. {
  95. /* I/O redirection methods */
  96. syslog_putc_t sc_putc; /* Normal buffered output */
  97. syslog_putc_t sc_force; /* Low-level output for interrupt handlers */
  98. syslog_flush_t sc_flush; /* Flush buffered output (on crash) */
  99. #ifdef CONFIG_SYSLOG_WRITE
  100. syslog_write_t sc_write; /* Write multiple bytes */
  101. #endif
  102. /* Implementation specific logic may follow */
  103. };
  104. /****************************************************************************
  105. * Public Data
  106. ****************************************************************************/
  107. #ifndef __ASSEMBLY__
  108. #ifdef __cplusplus
  109. #define EXTERN extern "C"
  110. extern "C"
  111. {
  112. #else
  113. #define EXTERN extern
  114. #endif
  115. /****************************************************************************
  116. * Public Function Prototypes
  117. ****************************************************************************/
  118. /****************************************************************************
  119. * Name: syslog_channel
  120. *
  121. * Description:
  122. * Configure the SYSLOGging function to use the provided channel to
  123. * generate SYSLOG output.
  124. *
  125. * Input Parameters:
  126. * channel - Provides the interface to the channel to be used.
  127. *
  128. * Returned Value:
  129. * Zero (OK)is returned on success. A negated errno value is returned
  130. * on any failure.
  131. *
  132. ****************************************************************************/
  133. int syslog_channel(FAR const struct syslog_channel_s *channel);
  134. /****************************************************************************
  135. * Name: syslog_initialize
  136. *
  137. * Description:
  138. * One power up, the SYSLOG facility is non-existent or limited to very
  139. * low-level output. This function is called later in the initialization
  140. * sequence after full driver support has been initialized. It installs
  141. * the configured SYSLOG drivers and enables full SYSLOGing capability.
  142. *
  143. * This function performs these basic operations:
  144. *
  145. * - Initialize the SYSLOG device
  146. * - Call syslog_channel() to begin using that device.
  147. *
  148. * If CONFIG_ARCH_SYSLOG is selected, then the architecture-specifica
  149. * logic will provide its own SYSLOG device initialize which must include
  150. * as a minimum a call to syslog_channel() to use the device.
  151. *
  152. * Input Parameters:
  153. * None
  154. *
  155. * Returned Value:
  156. * Zero (OK) is returned on success; a negated errno value is returned on
  157. * any failure.
  158. *
  159. ****************************************************************************/
  160. #ifndef CONFIG_ARCH_SYSLOG
  161. int syslog_initialize(void);
  162. #else
  163. # define syslog_initialize()
  164. #endif
  165. /****************************************************************************
  166. * Name: syslog_file_channel
  167. *
  168. * Description:
  169. * Configure to use a file in a mounted file system at 'devpath' as the
  170. * SYSLOG channel.
  171. *
  172. * This tiny function is simply a wrapper around syslog_dev_initialize()
  173. * and syslog_channel(). It calls syslog_dev_initialize() to configure
  174. * the character file at 'devpath then calls syslog_channel() to use that
  175. * device as the SYSLOG output channel.
  176. *
  177. * File SYSLOG channels differ from other SYSLOG channels in that they
  178. * cannot be established until after fully booting and mounting the target
  179. * file system. This function would need to be called from board-specific
  180. * bring-up logic AFTER mounting the file system containing 'devpath'.
  181. *
  182. * SYSLOG data generated prior to calling syslog_file_channel will, of
  183. * course, not be included in the file.
  184. *
  185. * NOTE interrupt level SYSLOG output will be lost in this case unless
  186. * the interrupt buffer is used.
  187. *
  188. * Input Parameters:
  189. * devpath - The full path to the file to be used for SYSLOG output.
  190. * This may be an existing file or not. If the file exists,
  191. * syslog_file_channel() will append new SYSLOG data to the end of the
  192. * file. If it does not, then syslog_file_channel() will create the
  193. * file.
  194. *
  195. * Returned Value:
  196. * Zero (OK) is returned on success; a negated errno value is returned on
  197. * any failure.
  198. *
  199. ****************************************************************************/
  200. #ifdef CONFIG_SYSLOG_FILE
  201. int syslog_file_channel(FAR const char *devpath);
  202. #endif
  203. /****************************************************************************
  204. * Name: syslog_flush
  205. *
  206. * Description:
  207. * This is called by system crash-handling logic. It must flush any
  208. * buffered data to the SYSLOG device.
  209. *
  210. * Interrupts are disabled at the time of the crash and this logic must
  211. * perform the flush using low-level, non-interrupt driven logic.
  212. *
  213. * REVISIT: There is an implementation problem in that if a character
  214. * driver is the underlying device, then there is no mechanism to flush
  215. * the data buffered in the driver with interrupts disabled.
  216. *
  217. * Currently, this function on (a) dumps the interrupt buffer (if the
  218. * SYSLOG interrupt buffer is enabled), and (b) only the SYSLOG interface
  219. * supports supports the 'sc_force()' method.
  220. *
  221. * Input Parameters:
  222. * None
  223. *
  224. * Returned Value:
  225. * Zero (OK)is returned on success. A negated errno value is returned
  226. * on any failure.
  227. *
  228. ****************************************************************************/
  229. int syslog_flush(void);
  230. /****************************************************************************
  231. * Name: nx_vsyslog
  232. *
  233. * Description:
  234. * nx_vsyslog() handles the system logging system calls. It is functionally
  235. * equivalent to vsyslog() except that (1) the per-process priority
  236. * filtering has already been performed and the va_list parameter is
  237. * passed by reference. That is because the va_list is a structure in
  238. * some compilers and passing of structures in the NuttX sycalls does
  239. * not work.
  240. *
  241. ****************************************************************************/
  242. int nx_vsyslog(int priority, FAR const IPTR char *src, FAR va_list *ap);
  243. #undef EXTERN
  244. #ifdef __cplusplus
  245. }
  246. #endif
  247. #endif /* __ASSEMBLY__ */
  248. #endif /* __INCLUDE_NUTTX_SYSLOG_SYSLOG_H */