1faeb2ff3SJohn Scipione/* 2*6fa3716cSAugustin Cavalier * Copyright 2007-2022 Haiku, Inc. All rights reserved. 3faeb2ff3SJohn Scipione * Distributed under the terms of the MIT License. 4faeb2ff3SJohn Scipione * 5faeb2ff3SJohn Scipione * Authors: 6faeb2ff3SJohn Scipione * Axel D�rfler 7faeb2ff3SJohn Scipione * Niels Sascha Reedijk, niels.reedijk@gmail.com 8faeb2ff3SJohn Scipione * 9faeb2ff3SJohn Scipione * Corresponds to: 10faeb2ff3SJohn Scipione * headers/posix/syslog.h rev 6684 11faeb2ff3SJohn Scipione */ 12faeb2ff3SJohn Scipione 13faeb2ff3SJohn Scipione 14faeb2ff3SJohn Scipione/*! 15faeb2ff3SJohn Scipione \file syslog.h 16faeb2ff3SJohn Scipione \ingroup libroot 17faeb2ff3SJohn Scipione \brief System logging capabilities 18faeb2ff3SJohn Scipione 19*6fa3716cSAugustin Cavalier The syslog service is provided by a server in the background, the syslog_daemon. 20*6fa3716cSAugustin Cavalier 21*6fa3716cSAugustin Cavalier After it has been started during the system's boot process, it will just sit there and wait for messages. Every call to syslog() or log_thread/team() will pass a message to the server containing information about what should be written to the log and with what options. The message is not a BMessage, but a plain data structure that can be created without any knowledge about BMessages. That is needed, because the service is used by the kernel as well. 22*6fa3716cSAugustin Cavalier 23*6fa3716cSAugustin Cavalier The server then just passes on that message to its internal handlers. It has two built-in handlers. One of them just processes the message and dumps a formatted text to the syslog file at /var/log/syslog. The other one creates a standard BMessage out of the message and broadcasts it to all of its listeners. 24*6fa3716cSAugustin Cavalier 25*6fa3716cSAugustin Cavalier If the syslog file reaches a certain size (by default 512 kB), it will be renamed to syslog.old, and a new syslog file is created. 26*6fa3716cSAugustin Cavalier 27*6fa3716cSAugustin Cavalier The first call of a function that will connect to the syslog service will create a syslog session. It's important to know that there is one session for each thread that uses the service, as well as one extra session for all team-wide logging functions. 28*6fa3716cSAugustin Cavalier 29*6fa3716cSAugustin Cavalier The original POSIX API as well as part of the additional BeOS API both use thread specific sessions. When a session is started, it will inherit the options defined for the team session. That means you can set logging options that every thread in your application will respect (if you don't overwrite them locally). But in order to define team wide options, you have to specifically use the BeOS-specific team API. 30faeb2ff3SJohn Scipione*/ 31faeb2ff3SJohn Scipione 32faeb2ff3SJohn Scipione 33faeb2ff3SJohn Scipione/*! 34faeb2ff3SJohn Scipione \fn void closelog(void) 35*6fa3716cSAugustin Cavalier \brief Closes the thread session, and frees all associated data 36*6fa3716cSAugustin Cavalier 37*6fa3716cSAugustin Cavalier The next call to the syslog service will start a new session, and will inherit the team log options at that point again. 38faeb2ff3SJohn Scipione*/ 39faeb2ff3SJohn Scipione 40faeb2ff3SJohn Scipione 41faeb2ff3SJohn Scipione/*! 42faeb2ff3SJohn Scipione \fn void openlog(const char *ident, int options, int facility) 43faeb2ff3SJohn Scipione \brief Starts a log session, and sets some output options 44faeb2ff3SJohn Scipione 45faeb2ff3SJohn Scipione Like openlog_thread() this function defines the log session in thread context; the 46faeb2ff3SJohn Scipione global options set by openlog_team() are not affected by this function. 47faeb2ff3SJohn Scipione*/ 48faeb2ff3SJohn Scipione 49faeb2ff3SJohn Scipione 50faeb2ff3SJohn Scipione/*! 51faeb2ff3SJohn Scipione \fn int setlogmask(int priorityMask) 52faeb2ff3SJohn Scipione \brief sets the logging priority mask 53faeb2ff3SJohn Scipione*/ 54faeb2ff3SJohn Scipione 55faeb2ff3SJohn Scipione 56faeb2ff3SJohn Scipione/*! 57faeb2ff3SJohn Scipione \fn void syslog(int priority, const char *message, ...) 58faeb2ff3SJohn Scipione \brief sends a message to the system log 59faeb2ff3SJohn Scipione*/ 60faeb2ff3SJohn Scipione 61faeb2ff3SJohn Scipione 62faeb2ff3SJohn Scipione/*! 63faeb2ff3SJohn Scipione \fn void closelog_team(void) 64*6fa3716cSAugustin Cavalier \brief Closes the current session 65*6fa3716cSAugustin Cavalier 66*6fa3716cSAugustin Cavalier This has currently no effect for the team logging functions. 67faeb2ff3SJohn Scipione*/ 68faeb2ff3SJohn Scipione 69faeb2ff3SJohn Scipione 70faeb2ff3SJohn Scipione/*! 71faeb2ff3SJohn Scipione \fn void openlog_team(const char *ident, int logopt, int facility) 72faeb2ff3SJohn Scipione \brief Starts a log session, and sets some output options 73faeb2ff3SJohn Scipione 74faeb2ff3SJohn Scipione This function defines the team-wide logging options. Thread local sessions 75faeb2ff3SJohn Scipione started with openlog() or openlog_thread() will inherit the options of the 76faeb2ff3SJohn Scipione global session. 77*6fa3716cSAugustin Cavalier 78*6fa3716cSAugustin Cavalier \param ident The identification string that is prepended to every message from your team. 79*6fa3716cSAugustin Cavalier \param logopt Logging option(s). 80*6fa3716cSAugustin Cavalier \param facility Specifies from what facility your message has been sent; for most cases this should just be LOG_USER. 81faeb2ff3SJohn Scipione*/ 82faeb2ff3SJohn Scipione 83faeb2ff3SJohn Scipione 84faeb2ff3SJohn Scipione/*! 85faeb2ff3SJohn Scipione \fn void log_team(int priority, const char *message, ...) 86*6fa3716cSAugustin Cavalier \brief Sends a message of the specified priority to the syslog daemon. 87faeb2ff3SJohn Scipione*/ 88faeb2ff3SJohn Scipione 89faeb2ff3SJohn Scipione 90faeb2ff3SJohn Scipione/*! 91faeb2ff3SJohn Scipione \fn int setlogmask_team(int priorityMask) 92*6fa3716cSAugustin Cavalier \brief Sets the logging priority mask 93*6fa3716cSAugustin Cavalier 94*6fa3716cSAugustin Cavalier Use the LOG_MASK() macro to build a mask of priorities to show. All messages of other priorities will be discarded. Example uses: 95*6fa3716cSAugustin Cavalier 96*6fa3716cSAugustin Cavalier\code 97*6fa3716cSAugustin Cavaliersetlogmask_team(LOG_MASK(LOG_WARNING)); 98*6fa3716cSAugustin Cavalier // all messages of priority LOG_WARNING will be shown 99*6fa3716cSAugustin Cavalier 100*6fa3716cSAugustin Cavaliersetlogmask_team(LOG_MASK(LOG_ERR + 1) - 1); 101*6fa3716cSAugustin Cavalier // all messages with a priority level higher than LOG_ERR will be shown 102*6fa3716cSAugustin Cavalier\endcode 103faeb2ff3SJohn Scipione*/ 104faeb2ff3SJohn Scipione 105faeb2ff3SJohn Scipione 106faeb2ff3SJohn Scipione/*! 107faeb2ff3SJohn Scipione \fn void closelog_thread(void) 108faeb2ff3SJohn Scipione \brief Closes the log 109faeb2ff3SJohn Scipione*/ 110faeb2ff3SJohn Scipione 111faeb2ff3SJohn Scipione 112faeb2ff3SJohn Scipione/*! 113faeb2ff3SJohn Scipione \fn void openlog_thread(const char *ident, int logopt, int facility) 114faeb2ff3SJohn Scipione \brief Starts a log session, and sets some output options 115faeb2ff3SJohn Scipione*/ 116faeb2ff3SJohn Scipione 117faeb2ff3SJohn Scipione 118faeb2ff3SJohn Scipione/*! 119faeb2ff3SJohn Scipione \fn void log_thread(int priority, const char *message, ...) 120faeb2ff3SJohn Scipione \brief sends a message to the system log 121faeb2ff3SJohn Scipione*/ 122faeb2ff3SJohn Scipione 123faeb2ff3SJohn Scipione 124faeb2ff3SJohn Scipione/*! 125faeb2ff3SJohn Scipione \fn int setlogmask_thread(int priorityMask) 126faeb2ff3SJohn Scipione \brief sets the logging priority mask 127faeb2ff3SJohn Scipione*/ 128faeb2ff3SJohn Scipione 129faeb2ff3SJohn Scipione 130faeb2ff3SJohn Scipione/*! 131faeb2ff3SJohn Scipione \name Options for openlog() 132faeb2ff3SJohn Scipione*/ 133faeb2ff3SJohn Scipione 134faeb2ff3SJohn Scipione 135faeb2ff3SJohn Scipione//! @{ 136faeb2ff3SJohn Scipione 137faeb2ff3SJohn Scipione 138faeb2ff3SJohn Scipione/*! 139faeb2ff3SJohn Scipione \def LOG_PID 140faeb2ff3SJohn Scipione \brief Log the process (thread/team) ID with each message 141faeb2ff3SJohn Scipione*/ 142faeb2ff3SJohn Scipione 143faeb2ff3SJohn Scipione 144faeb2ff3SJohn Scipione/*! 145faeb2ff3SJohn Scipione \def LOG_CONS 146*6fa3716cSAugustin Cavalier \brief If the message cannot be delivered to the syslog daemon, it will be directly dumped to stderr. 147faeb2ff3SJohn Scipione*/ 148faeb2ff3SJohn Scipione 149faeb2ff3SJohn Scipione 150faeb2ff3SJohn Scipione/*! 151faeb2ff3SJohn Scipione \def LOG_ODELAY 152faeb2ff3SJohn Scipione \brief Delay open until syslog() is called 153faeb2ff3SJohn Scipione*/ 154faeb2ff3SJohn Scipione 155faeb2ff3SJohn Scipione 156faeb2ff3SJohn Scipione/*! 157faeb2ff3SJohn Scipione \def LOG_NDELAY 158faeb2ff3SJohn Scipione \brief Connect to the syslog daemon immediately 159faeb2ff3SJohn Scipione*/ 160faeb2ff3SJohn Scipione 161faeb2ff3SJohn Scipione 162faeb2ff3SJohn Scipione/*! 163faeb2ff3SJohn Scipione \def LOG_SERIAL 164faeb2ff3SJohn Scipione \brief Dump to serial output as well. 165faeb2ff3SJohn Scipione \attention This is not yet implemented 166faeb2ff3SJohn Scipione*/ 167faeb2ff3SJohn Scipione 168faeb2ff3SJohn Scipione 169faeb2ff3SJohn Scipione/*! 170faeb2ff3SJohn Scipione \def LOG_PERROR 171*6fa3716cSAugustin Cavalier \brief The message will not only be sent to the syslog daemon, it will also be written to the application's stderr (unconditionally). 172faeb2ff3SJohn Scipione*/ 173faeb2ff3SJohn Scipione 174faeb2ff3SJohn Scipione 175faeb2ff3SJohn Scipione/*! 176faeb2ff3SJohn Scipione \def LOG_NOWAIT 177faeb2ff3SJohn Scipione \brief Do not wait for child processes 178faeb2ff3SJohn Scipione*/ 179faeb2ff3SJohn Scipione 180faeb2ff3SJohn Scipione 181faeb2ff3SJohn Scipione//! @} 182faeb2ff3SJohn Scipione 183faeb2ff3SJohn Scipione 184faeb2ff3SJohn Scipione/*! \name Facilities for openlog() 185faeb2ff3SJohn Scipione*/ 186faeb2ff3SJohn Scipione 187faeb2ff3SJohn Scipione 188faeb2ff3SJohn Scipione//! @{ 189faeb2ff3SJohn Scipione 190faeb2ff3SJohn Scipione 191faeb2ff3SJohn Scipione/*! 192faeb2ff3SJohn Scipione \def LOG_KERN 193faeb2ff3SJohn Scipione \brief Reserved for messages generated by the kernel. 194faeb2ff3SJohn Scipione*/ 195faeb2ff3SJohn Scipione 196faeb2ff3SJohn Scipione 197faeb2ff3SJohn Scipione/*! 198faeb2ff3SJohn Scipione \def LOG_USER 199faeb2ff3SJohn Scipione \brief Reserved for messages generated by user processes. 200faeb2ff3SJohn Scipione*/ 201faeb2ff3SJohn Scipione 202faeb2ff3SJohn Scipione 203faeb2ff3SJohn Scipione/*! 204faeb2ff3SJohn Scipione \def LOG_MAIL 205faeb2ff3SJohn Scipione \brief Standard (?) POSIX facility for messages by the mailing daemon. 206faeb2ff3SJohn Scipione*/ 207faeb2ff3SJohn Scipione 208faeb2ff3SJohn Scipione 209faeb2ff3SJohn Scipione/*! 210faeb2ff3SJohn Scipione \def LOG_DAEMON 211faeb2ff3SJohn Scipione \brief Standard POSIX (?) facility for messages by daemons (and Haiku servers). 212faeb2ff3SJohn Scipione*/ 213faeb2ff3SJohn Scipione 214faeb2ff3SJohn Scipione 215faeb2ff3SJohn Scipione/*! 216faeb2ff3SJohn Scipione \def LOG_AUTH 217faeb2ff3SJohn Scipione \brief Standard POSIX facility(?) for messages by the authentication services. 218faeb2ff3SJohn Scipione*/ 219faeb2ff3SJohn Scipione 220faeb2ff3SJohn Scipione 221faeb2ff3SJohn Scipione/*! 222faeb2ff3SJohn Scipione \def LOG_SYSLOG 223faeb2ff3SJohn Scipione \brief Reserved for messages generated by the syslog daemon. 224faeb2ff3SJohn Scipione*/ 225faeb2ff3SJohn Scipione 226faeb2ff3SJohn Scipione 227faeb2ff3SJohn Scipione/*! 228faeb2ff3SJohn Scipione \def LOG_LPR 229faeb2ff3SJohn Scipione \brief Reserved for messages generated by the UNIX lpr printing tool. 230faeb2ff3SJohn Scipione*/ 231faeb2ff3SJohn Scipione 232faeb2ff3SJohn Scipione 233faeb2ff3SJohn Scipione/*! 234faeb2ff3SJohn Scipione \def LOG_NEWS 235faeb2ff3SJohn Scipione \brief Reserved for messages generated by something UNIXy that does something with NEWS. 236faeb2ff3SJohn Scipione*/ 237faeb2ff3SJohn Scipione 238faeb2ff3SJohn Scipione 239faeb2ff3SJohn Scipione/*! 240faeb2ff3SJohn Scipione \def LOG_UUCP 241faeb2ff3SJohn Scipione \brief Reserved for messages generated by UUCP 242faeb2ff3SJohn Scipione*/ 243faeb2ff3SJohn Scipione 244faeb2ff3SJohn Scipione 245faeb2ff3SJohn Scipione/*! 246faeb2ff3SJohn Scipione \def LOG_CRON 247faeb2ff3SJohn Scipione \brief Reserved for messages generated by the CRON daemon. 248faeb2ff3SJohn Scipione*/ 249faeb2ff3SJohn Scipione 250faeb2ff3SJohn Scipione 251faeb2ff3SJohn Scipione/*! 252faeb2ff3SJohn Scipione \def LOG_AUTHPRIV 253faeb2ff3SJohn Scipione \brief Reserved for private (?) messages that relate to authentication. 254faeb2ff3SJohn Scipione*/ 255faeb2ff3SJohn Scipione 256faeb2ff3SJohn Scipione 257faeb2ff3SJohn Scipione/*! 258faeb2ff3SJohn Scipione \def LOG_LOCAL0 259faeb2ff3SJohn Scipione \brief For local use. 260faeb2ff3SJohn Scipione*/ 261faeb2ff3SJohn Scipione 262faeb2ff3SJohn Scipione 263faeb2ff3SJohn Scipione/*! 264faeb2ff3SJohn Scipione \def LOG_LOCAL1 265faeb2ff3SJohn Scipione \brief For local use. 266faeb2ff3SJohn Scipione*/ 267faeb2ff3SJohn Scipione 268faeb2ff3SJohn Scipione 269faeb2ff3SJohn Scipione/*! 270faeb2ff3SJohn Scipione \def LOG_LOCAL2 271faeb2ff3SJohn Scipione \brief For local use. 272faeb2ff3SJohn Scipione*/ 273faeb2ff3SJohn Scipione 274faeb2ff3SJohn Scipione 275faeb2ff3SJohn Scipione/*! 276faeb2ff3SJohn Scipione \def LOG_LOCAL3 277faeb2ff3SJohn Scipione \brief For local use. 278faeb2ff3SJohn Scipione*/ 279faeb2ff3SJohn Scipione 280faeb2ff3SJohn Scipione 281faeb2ff3SJohn Scipione/*! 282faeb2ff3SJohn Scipione \def LOG_LOCAL4 283faeb2ff3SJohn Scipione \brief For local use. 284faeb2ff3SJohn Scipione*/ 285faeb2ff3SJohn Scipione 286faeb2ff3SJohn Scipione 287faeb2ff3SJohn Scipione/*! 288faeb2ff3SJohn Scipione \def LOG_LOCAL5 289faeb2ff3SJohn Scipione \brief For local use. 290faeb2ff3SJohn Scipione*/ 291faeb2ff3SJohn Scipione 292faeb2ff3SJohn Scipione 293faeb2ff3SJohn Scipione/*! 294faeb2ff3SJohn Scipione \def LOG_LOCAL6 295faeb2ff3SJohn Scipione \brief For local use. 296faeb2ff3SJohn Scipione*/ 297faeb2ff3SJohn Scipione 298faeb2ff3SJohn Scipione 299faeb2ff3SJohn Scipione/*! 300faeb2ff3SJohn Scipione \def LOG_LOCAL7 301faeb2ff3SJohn Scipione \brief For local use. 302faeb2ff3SJohn Scipione*/ 303faeb2ff3SJohn Scipione 304faeb2ff3SJohn Scipione 305faeb2ff3SJohn Scipione//! @} 306faeb2ff3SJohn Scipione 307faeb2ff3SJohn Scipione 308faeb2ff3SJohn Scipione/*! 309faeb2ff3SJohn Scipione \name Priorities for syslog(), log_team() and log_thread() 310faeb2ff3SJohn Scipione*/ 311faeb2ff3SJohn Scipione 312faeb2ff3SJohn Scipione 313faeb2ff3SJohn Scipione//! @{ 314faeb2ff3SJohn Scipione 315faeb2ff3SJohn Scipione 316faeb2ff3SJohn Scipione/*! 317faeb2ff3SJohn Scipione \def LOG_EMERG 318faeb2ff3SJohn Scipione \brief A panic condition 319faeb2ff3SJohn Scipione*/ 320faeb2ff3SJohn Scipione 321faeb2ff3SJohn Scipione 322faeb2ff3SJohn Scipione/*! 323faeb2ff3SJohn Scipione \def LOG_PANIC 324faeb2ff3SJohn Scipione \brief An alias for LOG_EMERG 325faeb2ff3SJohn Scipione*/ 326faeb2ff3SJohn Scipione 327faeb2ff3SJohn Scipione 328faeb2ff3SJohn Scipione/*! 329faeb2ff3SJohn Scipione \def LOG_ALERT 330faeb2ff3SJohn Scipione \brief A condition to that should be corrected immediately 331faeb2ff3SJohn Scipione*/ 332faeb2ff3SJohn Scipione 333faeb2ff3SJohn Scipione 334faeb2ff3SJohn Scipione/*! 335faeb2ff3SJohn Scipione \def LOG_CRIT 336faeb2ff3SJohn Scipione \brief Critical conditions like hard drive errors 337faeb2ff3SJohn Scipione*/ 338faeb2ff3SJohn Scipione 339faeb2ff3SJohn Scipione 340faeb2ff3SJohn Scipione/*! 341faeb2ff3SJohn Scipione \def LOG_ERR 342faeb2ff3SJohn Scipione \brief Errors 343faeb2ff3SJohn Scipione*/ 344faeb2ff3SJohn Scipione 345faeb2ff3SJohn Scipione 346faeb2ff3SJohn Scipione/*! 347faeb2ff3SJohn Scipione \def LOG_WARNING 348faeb2ff3SJohn Scipione \brief Warnings 349faeb2ff3SJohn Scipione*/ 350faeb2ff3SJohn Scipione 351faeb2ff3SJohn Scipione 352faeb2ff3SJohn Scipione/*! 353faeb2ff3SJohn Scipione \def LOG_NOTICE 354faeb2ff3SJohn Scipione \brief Notices, instructions on how to use certain configuration options. 355faeb2ff3SJohn Scipione*/ 356faeb2ff3SJohn Scipione 357faeb2ff3SJohn Scipione 358faeb2ff3SJohn Scipione/*! 359faeb2ff3SJohn Scipione \def LOG_INFO 360faeb2ff3SJohn Scipione \brief Information, like versions and so. 361faeb2ff3SJohn Scipione*/ 362faeb2ff3SJohn Scipione 363faeb2ff3SJohn Scipione 364faeb2ff3SJohn Scipione/*! 365faeb2ff3SJohn Scipione \def LOG_DEBUG 366faeb2ff3SJohn Scipione \brief Debug information. 367faeb2ff3SJohn Scipione*/ 368faeb2ff3SJohn Scipione 369faeb2ff3SJohn Scipione 370faeb2ff3SJohn Scipione//! @} 371faeb2ff3SJohn Scipione 372faeb2ff3SJohn Scipione 373faeb2ff3SJohn Scipione/*! 374faeb2ff3SJohn Scipione \def LOG_MASK 375faeb2ff3SJohn Scipione \brief Converts a priority definition for use in setlogmask() 376faeb2ff3SJohn Scipione*/ 377