1 /**************************************************************************** 2 * include/syslog.h 3 * 4 * Copyright (C) 2013-2014, 2018 Gregory Nutt. All rights reserved. 5 * Author: Gregory Nutt <gnutt@nuttx.org> 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 3. Neither the name NuttX nor the names of its contributors may be 18 * used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 * POSSIBILITY OF SUCH DAMAGE. 33 * 34 ****************************************************************************/ 35 36 #ifndef __INCLUDE_SYSLOG_H 37 #define __INCLUDE_SYSLOG_H 38 39 /**************************************************************************** 40 * Included Files 41 ****************************************************************************/ 42 43 #include "vfs_config.h" 44 45 #include "stdint.h" 46 #include "stdarg.h" 47 48 #ifdef __cplusplus 49 #if __cplusplus 50 extern "C"{ 51 #endif 52 #endif /* __cplusplus */ 53 54 /**************************************************************************** 55 * Pre-processor Definitions 56 ****************************************************************************/ 57 /* The option argument to openlog() is an OR of any of these: 58 * 59 * LOG_CONS - Write directly to system console if there is an error 60 * while sending to system logger. 61 * LOG_NDELAY - Open the connection immediately (normally, the connection 62 * is opened when the first message is logged). 63 * LOG_NOWAIT - Don't wait for child processes that may have been created 64 * while logging the message. 65 * LOG_ODELAY - The converse of LOG_NDELAY; opening of the connection is 66 * delayed until syslog() is called. (This is the default, 67 * and need not be specified.) 68 * LOG_PERROR - (Not in POSIX.1-2001 or POSIX.1-2008.) Print to stderr 69 * as well (Linux). 70 * LOG_PID - Include PID with each message. 71 */ 72 73 /* Note: openlog() is not currently supported */ 74 75 /* The facility argument is used to specify what type of program is logging 76 * the message. This lets the configuration file specify that messages from 77 * different facilities will be handled differently. 78 * 79 * LOG_AUTH - Security/authorization messages 80 * LOG_AUTHPRIV - Security/authorization messages (private) 81 * LOG_CRON - Clock daemon (cron and at) 82 * LOG_DAEMON - System daemons without separate facility value 83 * LOG_FTP - Ftp daemon 84 * LOG_KERN - Lernel messages (these can't be generated from user 85 * processes) 86 * LOG_LOCAL0 through LOG_LOCAL7 - Reserved for local use 87 * LOG_LPR - Line printer subsystem 88 * LOG_MAIL - Mail subsystem 89 * LOG_NEWS - USENET news subsystem 90 * LOG_SYSLOG - Messages generated internally by syslogd(8) 91 * LOG_USER - Generic user-level messages (default) 92 * LOG_UUCP - UUCP subsystem 93 */ 94 95 #define LOG_AUTH 0 96 #define LOG_AUTHPRIV 0 97 #define LOG_CRON 0 98 #define LOG_DAEMON 0 99 #define LOG_FTP 0 100 #define LOG_KERN 0 101 #define LOG_LOCAL0 0 102 #define LOG_LOCAL1 0 103 #define LOG_LOCAL2 0 104 #define LOG_LOCAL3 0 105 #define LOG_LOCAL4 0 106 #define LOG_LOCAL5 0 107 #define LOG_LOCAL6 0 108 #define LOG_LOCAL7 0 109 #define LOG_LPR 0 110 #define LOG_MAIL 0 111 #define LOG_NEWS 0 112 #define LOG_SYSLOG 0 113 #define LOG_USER 0 114 #define LOG_UUCP 0 115 116 /* This determines the importance of the message. The levels are, in order 117 * of decreasing importance: 118 */ 119 120 #define LOG_EMERG 0 /* System is unusable */ 121 #define LOG_ALERT 1 /* Action must be taken immediately */ 122 #define LOG_CRIT 2 /* Critical conditions */ 123 #define LOG_ERR 3 /* Error conditions */ 124 #define LOG_WARNING 4 /* Warning conditions */ 125 #define LOG_NOTICE 5 /* Normal, but significant, condition */ 126 #define LOG_INFO 6 /* Informational message */ 127 #define LOG_DEBUG 7 /* Debug-level message */ 128 129 /* Used with setlogmask() */ 130 131 #define LOG_MASK(p) (1 << (p)) 132 #define LOG_UPTO(p) ((1 << (p)) - 1) 133 #define LOG_ALL 0xff 134 135 /**************************************************************************** 136 * Public Function Prototypes 137 ****************************************************************************/ 138 139 #if defined(CONFIG_SYSLOG_CHAR) && !defined(CONFIG_SYSLOG_DEVPATH) 140 # define CONFIG_SYSLOG_DEVPATH "/dev/ttyS1" 141 #endif 142 143 /**************************************************************************** 144 * Name: openlog 145 * 146 * Description: 147 * The openlog() function sets process attributes that affect subsequent 148 * calls to syslog(). The ident argument is a string that is prepended to 149 * every message. The logopt argument indicates logging options. Values 150 * for logopt are constructed by a bitwise-inclusive OR of zero or more of 151 * the following: 152 * 153 * LOG_PID - Log the process ID with each message. This is useful for 154 * identifying specific processes. 155 * 156 * LOG_CONS - Write messages to the system console if they cannot be 157 * sent to the logging facility. The syslog() function ensures that 158 * the process does not acquire the console as a controlling terminal 159 * in the process of writing the message. 160 * 161 * LOG_NDELAY - Open the connection to the logging facility immediately. 162 * Normally the open is delayed until the first message is logged. 163 * This is useful for programs that need to manage the order in which 164 * file descriptors are allocated. 165 * 166 * LOG_ODELAY - Delay open until syslog() is called. 167 * 168 * LOG_NOWAIT - Do not wait for child processes that may have been 169 * created during the course of logging the message. This option 170 * should be used by processes that enable notification of child 171 * termination using SIGCHLD, since syslog() may otherwise block 172 * waiting for a child whose exit status has already been collected. 173 * 174 * The facility argument encodes a default facility to be assigned to all 175 * messages that do not have an explicit facility already encoded. The 176 * initial default facility is LOG_USER. 177 * 178 * It is not necessary to call openlog() prior to calling syslog(). 179 * 180 ****************************************************************************/ 181 182 #if 0 /* Not supported */ 183 void openlog(FAR const char *ident, int option, int facility); 184 #endif 185 186 /**************************************************************************** 187 * Name: closelog 188 * 189 * Description: 190 * The openlog() and syslog() functions may allocate a file descriptor. 191 * The closelog() function will close any open file descriptors allocated 192 * by previous calls to openlog() or syslog(). 193 * 194 ****************************************************************************/ 195 196 #if 0 /* Not supported */ 197 void closelog(void); 198 #endif 199 200 /**************************************************************************** 201 * Name: syslog and vsyslog 202 * 203 * Description: 204 * syslog() generates a log message. The priority argument is formed by 205 * ORing the facility and the level values (see include/syslog.h). The 206 * remaining arguments are a format, as in printf and any arguments to the 207 * format. 208 * 209 * The NuttX implementation does not support any special formatting 210 * characters beyond those supported by printf. 211 * 212 * The function vsyslog() performs the same task as syslog() with the 213 * difference that it takes a set of arguments which have been obtained 214 * using the stdarg variable argument list macros. 215 * 216 ****************************************************************************/ 217 218 int syslog(int priority, const char *format, ...); 219 int vsyslog(int priority, const char *src, va_list ap); 220 221 /**************************************************************************** 222 * Name: lowsyslog and lowvsyslog 223 * 224 * Description: 225 * syslog() generates a log message. The priority argument is formed by 226 * ORing the facility and the level values (see include/syslog.h). The 227 * remaining arguments are a format, as in printf and any arguments to the 228 * format. 229 * 230 * This is a non-standard, low-level system logging interface. The 231 * difference between syslog() and lowsyslog() is that the syslog() 232 * interface writes to the syslog device (usually fd=1, stdout) whereas 233 * lowsyslog() uses a lower level interface that works even from interrupt 234 * handlers. 235 * 236 * If the platform cannot support lowsyslog, then we will substitute the 237 * standard syslogging functions. These will, however, probably cause 238 * problems if called from interrupt handlers, depending upon the nature of 239 * the underlying syslog device. 240 * 241 * The function lowvsyslog() performs the same task as lowsyslog() with 242 * the difference that it takes a set of arguments which have been 243 * obtained using the stdarg variable argument list macros. 244 * 245 ****************************************************************************/ 246 247 #ifdef CONFIG_ARCH_LOWPUTC 248 249 int lowsyslog(int priority, FAR const char *format, ...); 250 int lowvsyslog(int priority, FAR const char *format, va_list ap); 251 252 #else 253 254 # ifdef CONFIG_CPP_HAVE_VARARGS 255 # define lowsyslog(p,f,...) syslog(p,f,##__VA_ARGS__) 256 # else 257 # define lowsyslog (void) 258 # endif 259 # define lowvsyslog(p,f,a) vsyslog(p,f,a) 260 261 #endif 262 263 /**************************************************************************** 264 * Name: setlogmask 265 * 266 * Description: 267 * The setlogmask() function sets the logmask and returns the previous 268 * mask. If the mask argument is 0, the current logmask is not modified. 269 * 270 * The SYSLOG priorities are: LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, 271 * LOG_WARNING, LOG_NOTICE, LOG_INFO, and LOG_DEBUG. The bit corresponding 272 * to a priority p is LOG_MASK(p); LOG_UPTO(p) provides the mask of all 273 * priorities in the above list up to and including p. 274 * 275 * Per OpenGroup.org "If the maskpri argument is 0, the current log mask 276 * is not modified." In this implementation, the value zero is permitted 277 * in order to disable all syslog levels. 278 * 279 * REVISIT: Per POSIX the syslog mask should be a per-process value but in 280 * NuttX, the scope of the mask is dependent on the nature of the build: 281 * 282 * Flat Build: There is one, global SYSLOG mask that controls all output. 283 * Protected Build: There are two SYSLOG masks. One within the kernel 284 * that controls only kernel output. And one in user-space that controls 285 * only user SYSLOG output. 286 * Kernel Build: The kernel build is compliant with the POSIX requirement: 287 * There will be one mask for for each user process, controlling the 288 * SYSLOG output only form that process. There will be a separate mask 289 * accessable only in the kernel code to control kernel SYSLOG output. 290 * 291 ****************************************************************************/ 292 293 int setlogmask(int mask); 294 295 #ifdef __cplusplus 296 #if __cplusplus 297 } 298 #endif 299 #endif /* __cplusplus */ 300 301 #endif /* __INCLUDE_SYSLOG_H */ 302