Loading...
Searching...
No Matches
Macros | Functions
syslog.h File Reference

System logging capabilities. More...

Macros

#define LOG_MASK(pri)   (1 << (pri))
 Converts a priority definition for use in setlogmask()
 
Options for openlog()
#define LOG_CONS   (2 << 12) /* log to the system console on error */
 If the message cannot be delivered to the syslog daemon, it will be directly dumped to stderr.
 
#define LOG_NDELAY   (8 << 12) /* connect to the syslog daemon immediately */
 Connect to the syslog daemon immediately.
 
#define LOG_NOWAIT   (64 << 12) /* do not wait for child processes */
 Do not wait for child processes.
 
#define LOG_ODELAY   (4 << 12) /* delay open until syslog() is called */
 Delay open until syslog() is called.
 
#define LOG_PERROR   (32 << 12) /* dump to stderr as well */
 The message will not only be sent to the syslog daemon, it will also be written to the application's stderr (unconditionally).
 
#define LOG_PID   (1 << 12) /* log the process (thread/team) ID with each message */
 Log the process (thread/team) ID with each message.
 
#define LOG_SERIAL   (16 << 12) /* dump to serial output as well (not implemented) */
 Dump to serial output as well.
 
Facilities for openlog()
#define LOG_AUTH   (4 << 3)
 Standard POSIX facility(?) for messages by the authentication services.
 
#define LOG_AUTHPRIV   (10 << 3) /* security/authorization messages (private) */
 Reserved for private (?) messages that relate to authentication.
 
#define LOG_CRON   (9 << 3)
 Reserved for messages generated by the CRON daemon.
 
#define LOG_DAEMON   (3 << 3)
 Standard POSIX (?) facility for messages by daemons (and Haiku servers).
 
#define LOG_KERN   (0 << 3) /* messages generated by the kernel */
 Reserved for messages generated by the kernel.
 
#define LOG_LOCAL0   (16 << 3)
 For local use.
 
#define LOG_LOCAL1   (17 << 3)
 For local use.
 
#define LOG_LOCAL2   (18 << 3)
 For local use.
 
#define LOG_LOCAL3   (19 << 3)
 For local use.
 
#define LOG_LOCAL4   (20 << 3)
 For local use.
 
#define LOG_LOCAL5   (21 << 3)
 For local use.
 
#define LOG_LOCAL6   (22 << 3)
 For local use.
 
#define LOG_LOCAL7   (23 << 3)
 For local use.
 
#define LOG_LPR   (6 << 3)
 Reserved for messages generated by the UNIX lpr printing tool.
 
#define LOG_MAIL   (2 << 3)
 Standard (?) POSIX facility for messages by the mailing daemon.
 
#define LOG_NEWS   (7 << 3)
 Reserved for messages generated by something UNIXy that does something with NEWS.
 
#define LOG_SYSLOG   (5 << 3) /* messages generated internally by syslogd */
 Reserved for messages generated by the syslog daemon.
 
#define LOG_USER   (1 << 3) /* by user processes */
 Reserved for messages generated by user processes.
 
#define LOG_UUCP   (8 << 3)
 Reserved for messages generated by UUCP.
 
Priorities for syslog(), log_team() and log_thread()
#define LOG_ALERT   1 /* a condition that should be corrected immediately */
 A condition to that should be corrected immediately.
 
#define LOG_CRIT   2 /* critical conditions like hard drive errors */
 Critical conditions like hard drive errors.
 
#define LOG_DEBUG   7
 Debug information.
 
#define LOG_EMERG   0 /* a panic condition */
 A panic condition.
 
#define LOG_ERR   3
 Errors.
 
#define LOG_INFO   6
 Information, like versions and so.
 
#define LOG_NOTICE   5
 Notices, instructions on how to use certain configuration options.
 
#define LOG_PANIC   LOG_EMERG
 An alias for LOG_EMERG.
 
#define LOG_WARNING   4
 Warnings.
 

Functions

void closelog (void)
 Closes the thread session, and frees all associated data.
 
void closelog_team (void)
 Closes the current session.
 
void closelog_thread (void)
 Closes the log.
 
void log_team (int priority, const char *message,...)
 Sends a message of the specified priority to the syslog daemon.
 
void log_thread (int priority, const char *message,...)
 sends a message to the system log
 
void openlog (const char *ident, int options, int facility)
 Starts a log session, and sets some output options.
 
void openlog_team (const char *ident, int logopt, int facility)
 Starts a log session, and sets some output options.
 
void openlog_thread (const char *ident, int logopt, int facility)
 Starts a log session, and sets some output options.
 
int setlogmask (int priorityMask)
 sets the logging priority mask
 
int setlogmask_team (int priorityMask)
 Sets the logging priority mask.
 
int setlogmask_thread (int priorityMask)
 sets the logging priority mask
 
void syslog (int priority, const char *message,...)
 sends a message to the system log
 

Detailed Description

System logging capabilities.

The syslog service is provided by a server in the background, the syslog_daemon.

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.

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.

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.

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.

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.

Macro Definition Documentation

◆ LOG_SERIAL

#define LOG_SERIAL   (16 << 12) /* dump to serial output as well (not implemented) */

Dump to serial output as well.

Attention
This is not yet implemented

Function Documentation

◆ closelog()

void closelog ( void  )

Closes the thread session, and frees all associated data.

The next call to the syslog service will start a new session, and will inherit the team log options at that point again.

◆ closelog_team()

void closelog_team ( void  )

Closes the current session.

This has currently no effect for the team logging functions.

◆ openlog()

void openlog ( const char *  ident,
int  options,
int  facility 
)

Starts a log session, and sets some output options.

Like openlog_thread() this function defines the log session in thread context; the global options set by openlog_team() are not affected by this function.

◆ openlog_team()

void openlog_team ( const char *  ident,
int  logopt,
int  facility 
)

Starts a log session, and sets some output options.

This function defines the team-wide logging options. Thread local sessions started with openlog() or openlog_thread() will inherit the options of the global session.

Parameters
identThe identification string that is prepended to every message from your team.
logoptLogging option(s).
facilitySpecifies from what facility your message has been sent; for most cases this should just be LOG_USER.

◆ setlogmask_team()

int setlogmask_team ( int  priorityMask)

Sets the logging priority mask.

Use the LOG_MASK() macro to build a mask of priorities to show. All messages of other priorities will be discarded. Example uses:

// all messages of priority LOG_WARNING will be shown
// all messages with a priority level higher than LOG_ERR will be shown
#define LOG_MASK(pri)
Converts a priority definition for use in setlogmask()
Definition: syslog.h:68
int setlogmask_team(int priorityMask)
Sets the logging priority mask.
#define LOG_ERR
Errors.
Definition: syslog.h:58
#define LOG_WARNING
Warnings.
Definition: syslog.h:59