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