syslog.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /****************************************************************************
  2. * include/syslog.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __INCLUDE_SYSLOG_H
  21. #define __INCLUDE_SYSLOG_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <nuttx/compiler.h>
  27. #include <stdint.h>
  28. #include <stdarg.h>
  29. #include <stdbool.h>
  30. /****************************************************************************
  31. * Pre-processor Definitions
  32. ****************************************************************************/
  33. /* The option argument to openlog() is an OR of any of these:
  34. *
  35. * LOG_CONS - Write directly to system console if there is an error
  36. * while sending to system logger.
  37. * LOG_NDELAY - Open the connection immediately (normally, the connection
  38. * is opened when the first message is logged).
  39. * LOG_NOWAIT - Don't wait for child processes that may have been created
  40. * while logging the message.
  41. * LOG_ODELAY - The converse of LOG_NDELAY; opening of the connection is
  42. * delayed until syslog() is called. (This is the default,
  43. * and need not be specified.)
  44. * LOG_PERROR - (Not in POSIX.1-2001 or POSIX.1-2008.) Print to stderr
  45. * as well (Linux).
  46. * LOG_PID - Include PID with each message.
  47. */
  48. /* Note: openlog() is not currently supported */
  49. /* The facility argument is used to specify what type of program is logging
  50. * the message. This lets the configuration file specify that messages from
  51. * different facilities will be handled differently.
  52. *
  53. * LOG_AUTH - Security/authorization messages
  54. * LOG_AUTHPRIV - Security/authorization messages (private)
  55. * LOG_CRON - Clock daemon (cron and at)
  56. * LOG_DAEMON - System daemons without separate facility value
  57. * LOG_FTP - FTP daemon
  58. * LOG_KERN - Kernel messages (these can't be generated from user
  59. * processes)
  60. * LOG_LOCAL0 through LOG_LOCAL7 - Reserved for local use
  61. * LOG_LPR - Line printer subsystem
  62. * LOG_MAIL - Mail subsystem
  63. * LOG_NEWS - USENET news subsystem
  64. * LOG_SYSLOG - Messages generated internally by syslogd(8)
  65. * LOG_USER - Generic user-level messages (default)
  66. * LOG_UUCP - UUCP subsystem
  67. */
  68. #define LOG_AUTH 0
  69. #define LOG_AUTHPRIV 0
  70. #define LOG_CRON 0
  71. #define LOG_DAEMON 0
  72. #define LOG_FTP 0
  73. #define LOG_KERN 0
  74. #define LOG_LOCAL0 0
  75. #define LOG_LOCAL1 0
  76. #define LOG_LOCAL2 0
  77. #define LOG_LOCAL3 0
  78. #define LOG_LOCAL4 0
  79. #define LOG_LOCAL5 0
  80. #define LOG_LOCAL6 0
  81. #define LOG_LOCAL7 0
  82. #define LOG_LPR 0
  83. #define LOG_MAIL 0
  84. #define LOG_NEWS 0
  85. #define LOG_SYSLOG 0
  86. #define LOG_USER 0
  87. #define LOG_UUCP 0
  88. /* This determines the importance of the message. The levels are, in order
  89. * of decreasing importance:
  90. */
  91. #define LOG_EMERG 0 /* System is unusable */
  92. #define LOG_ALERT 1 /* Action must be taken immediately */
  93. #define LOG_CRIT 2 /* Critical conditions */
  94. #define LOG_ERR 3 /* Error conditions */
  95. #define LOG_WARNING 4 /* Warning conditions */
  96. #define LOG_NOTICE 5 /* Normal, but significant, condition */
  97. #define LOG_INFO 6 /* Informational message */
  98. #define LOG_DEBUG 7 /* Debug-level message */
  99. /* Used with setlogmask() */
  100. #define LOG_MASK(p) (1 << (p))
  101. #define LOG_UPTO(p) ((1 << ((p)+1)) - 1)
  102. #define LOG_ALL 0xff
  103. /****************************************************************************
  104. * Public Function Prototypes
  105. ****************************************************************************/
  106. #if defined(__cplusplus)
  107. extern "C"
  108. {
  109. #endif
  110. /****************************************************************************
  111. * Name: openlog
  112. *
  113. * Description:
  114. * The openlog() function sets process attributes that affect subsequent
  115. * calls to syslog(). The ident argument is a string that is prepended to
  116. * every message. The logopt argument indicates logging options. Values
  117. * for logopt are constructed by a bitwise-inclusive OR of zero or more of
  118. * the following:
  119. *
  120. * LOG_PID - Log the process ID with each message. This is useful for
  121. * identifying specific processes.
  122. *
  123. * LOG_CONS - Write messages to the system console if they cannot be
  124. * sent to the logging facility. The syslog() function ensures that
  125. * the process does not acquire the console as a controlling terminal
  126. * in the process of writing the message.
  127. *
  128. * LOG_NDELAY - Open the connection to the logging facility immediately.
  129. * Normally the open is delayed until the first message is logged.
  130. * This is useful for programs that need to manage the order in which
  131. * file descriptors are allocated.
  132. *
  133. * LOG_ODELAY - Delay open until syslog() is called.
  134. *
  135. * LOG_NOWAIT - Do not wait for child processes that may have been
  136. * created during the course of logging the message. This option
  137. * should be used by processes that enable notification of child
  138. * termination using SIGCHLD, since syslog() may otherwise block
  139. * waiting for a child whose exit status has already been collected.
  140. *
  141. * The facility argument encodes a default facility to be assigned to all
  142. * messages that do not have an explicit facility already encoded. The
  143. * initial default facility is LOG_USER.
  144. *
  145. * It is not necessary to call openlog() prior to calling syslog().
  146. *
  147. ****************************************************************************/
  148. #if 0 /* Not supported */
  149. void openlog(FAR const char *ident, int option, int facility);
  150. #endif
  151. /****************************************************************************
  152. * Name: closelog
  153. *
  154. * Description:
  155. * The openlog() and syslog() functions may allocate a file descriptor.
  156. * The closelog() function will close any open file descriptors allocated
  157. * by previous calls to openlog() or syslog().
  158. *
  159. ****************************************************************************/
  160. #if 0 /* Not supported */
  161. void closelog(void);
  162. #endif
  163. /****************************************************************************
  164. * Name: syslog and vsyslog
  165. *
  166. * Description:
  167. * syslog() generates a log message. The priority argument is formed by
  168. * ORing the facility and the level values (see include/syslog.h). The
  169. * remaining arguments are a format, as in printf and any arguments to the
  170. * format.
  171. *
  172. * The NuttX implementation does not support any special formatting
  173. * characters beyond those supported by printf.
  174. *
  175. * The function vsyslog() performs the same task as syslog() with the
  176. * difference that it takes a set of arguments which have been obtained
  177. * using the stdarg variable argument list macros.
  178. *
  179. ****************************************************************************/
  180. void syslog(int priority, FAR const IPTR char *fmt, ...) sysloglike(2, 3);
  181. void vsyslog(int priority, FAR const IPTR char *fmt, va_list ap)
  182. sysloglike(2, 0);
  183. /****************************************************************************
  184. * Name: setlogmask
  185. *
  186. * Description:
  187. * The setlogmask() function sets the logmask and returns the previous
  188. * mask. If the mask argument is 0, the current logmask is not modified.
  189. *
  190. * The SYSLOG priorities are: LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
  191. * LOG_WARNING, LOG_NOTICE, LOG_INFO, and LOG_DEBUG. The bit corresponding
  192. * to a priority p is LOG_MASK(p); LOG_UPTO(p) provides the mask of all
  193. * priorities in the above list up to and including p.
  194. *
  195. * Per OpenGroup.org "If the maskpri argument is 0, the current log mask
  196. * is not modified." In this implementation, the value zero is permitted
  197. * in order to disable all syslog levels.
  198. *
  199. * NOTE: setlogmask is not a thread-safe, re-entrant function. Concurrent
  200. * use of setlogmask() will have undefined behavior.
  201. *
  202. * REVISIT: Per POSIX the syslog mask should be a per-process value but in
  203. * NuttX, the scope of the mask is dependent on the nature of the build:
  204. *
  205. * Flat Build: There is one, global SYSLOG mask that controls all output.
  206. * Protected Build: There are two SYSLOG masks. One within the kernel
  207. * that controls only kernel output. And one in user-space that controls
  208. * only user SYSLOG output.
  209. * Kernel Build: The kernel build is compliant with the POSIX requirement:
  210. * There will be one mask for for each user process, controlling the
  211. * SYSLOG output only form that process. There will be a separate mask
  212. * accessible only in the kernel code to control kernel SYSLOG output.
  213. *
  214. ****************************************************************************/
  215. int setlogmask(int mask);
  216. #if defined(__cplusplus)
  217. }
  218. #endif
  219. #endif /* __INCLUDE_SYSLOG_H */