1 /* The stdlog main header file
2  *
3  * Copyright (C) 2014 Adiscon GmbH
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY ADISCON AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL ADISCON OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef LIBLOGGING_STDLOG_H_INCLUDED
29 #define LIBLOGGING_STDLOG_H_INCLUDED
30 #include <stdint.h>
31 #include <stdlib.h>
32 #include <stdarg.h>
33 
34 /* options for stdlog_open() call */
35 #define STDLOG_SIGSAFE 1	/* enforce signal-safe implementation */
36 #define STDLOG_PID     2	/* log the PID with each message */
37 #define STDLOG_USE_DFLT_OPTS ((int)0x80000000)	/* use default options */
38 
39 /* traditional syslog facility codes */
40 #define	STDLOG_KERN	0	/* kernel messages */
41 #define	STDLOG_USER	1	/* random user-level messages */
42 #define	STDLOG_MAIL	2	/* mail system */
43 #define	STDLOG_DAEMON	3	/* system daemons */
44 #define	STDLOG_AUTH	4	/* security/authorization messages */
45 #define	STDLOG_SYSLOG	5	/* messages generated internally by syslogd */
46 #define	STDLOG_LPR	6	/* line printer subsystem */
47 #define	STDLOG_NEWS	7	/* network news subsystem */
48 #define	STDLOG_UUCP	8	/* UUCP subsystem */
49 #define	STDLOG_CRON	9	/* clock daemon */
50 #define	STDLOG_AUTHPRIV	10	/* security/authorization messages (private) */
51 #define	STDLOG_FTP	11	/* ftp daemon */
52 /* other codes through 15 reserved for system use */
53 #define	STDLOG_LOCAL0	16	/* reserved for local use */
54 #define	STDLOG_LOCAL1	17	/* reserved for local use */
55 #define	STDLOG_LOCAL2	18	/* reserved for local use */
56 #define	STDLOG_LOCAL3	19	/* reserved for local use */
57 #define	STDLOG_LOCAL4	20	/* reserved for local use */
58 #define	STDLOG_LOCAL5	21	/* reserved for local use */
59 #define	STDLOG_LOCAL6	22	/* reserved for local use */
60 #define	STDLOG_LOCAL7	23	/* reserved for local use */
61 
62 /* traditional syslog priorities */
63 #define	STDLOG_EMERG	0	/* system is unusable */
64 #define	STDLOG_ALERT	1	/* action must be taken immediately */
65 #define	STDLOG_CRIT	2	/* critical conditions */
66 #define	STDLOG_ERR	3	/* error conditions */
67 #define	STDLOG_WARNING	4	/* warning conditions */
68 #define	STDLOG_NOTICE	5	/* normal but significant condition */
69 #define	STDLOG_INFO	6	/* informational */
70 #define	STDLOG_DEBUG	7	/* debug-level messages */
71 
72 typedef struct stdlog_channel *stdlog_channel_t;
73 
74 const char *stdlog_version(void);
75 size_t stdlog_get_msgbuf_size(void);
76 const char *stdlog_get_dflt_chanspec(void);
77 int stdlog_init(uint32_t options);
78 void stdlog_deinit(void);
79 stdlog_channel_t stdlog_open(const char *ident, const int option, const int facility, const char *channelspec);
80 void stdlog_close(stdlog_channel_t channel);
81 int stdlog_log(stdlog_channel_t channel, const int severity, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
82 int stdlog_log_b(stdlog_channel_t ch, const int severity, char *wrkbuf, const size_t buflen, const char *fmt, ...);
83 int stdlog_vlog(stdlog_channel_t ch, const int severity, const char *fmt, va_list ap);
84 int stdlog_vlog_b(stdlog_channel_t ch, const int severity, char *__restrict__ const wrkbuf, const size_t buflen, const char *fmt, va_list ap);
85 
86 #endif /* multi-include protection */
87