26 #include "lwpa_bool.h"
56 #define LWPA_LOG_KERN (0 << 3)
57 #define LWPA_LOG_USER (1 << 3)
58 #define LWPA_LOG_MAIL (2 << 3)
59 #define LWPA_LOG_DAEMON (3 << 3)
60 #define LWPA_LOG_AUTH (4 << 3)
61 #define LWPA_LOG_SYSLOG (5 << 3)
63 #define LWPA_LOG_LPR (6 << 3)
64 #define LWPA_LOG_NEWS (7 << 3)
65 #define LWPA_LOG_UUCP (8 << 3)
66 #define LWPA_LOG_CRON (9 << 3)
67 #define LWPA_LOG_AUTHPRIV (10 << 3)
68 #define LWPA_LOG_FTP (11 << 3)
70 #define LWPA_LOG_LOCAL0 (16 << 3)
71 #define LWPA_LOG_LOCAL1 (17 << 3)
72 #define LWPA_LOG_LOCAL2 (18 << 3)
73 #define LWPA_LOG_LOCAL3 (19 << 3)
74 #define LWPA_LOG_LOCAL4 (20 << 3)
75 #define LWPA_LOG_LOCAL5 (21 << 3)
76 #define LWPA_LOG_LOCAL6 (22 << 3)
77 #define LWPA_LOG_LOCAL7 (23 << 3)
80 #define LWPA_LOG_NFACILITIES 24
81 #define LWPA_LOG_FACMASK 0x03f8
83 #define LWPA_LOG_FAC(p) (((p)&LWPA_LOG_FACMASK) >> 3)
88 #define LWPA_LOG_EMERG 0
89 #define LWPA_LOG_ALERT 1
90 #define LWPA_LOG_CRIT 2
91 #define LWPA_LOG_ERR 3
92 #define LWPA_LOG_WARNING 4
93 #define LWPA_LOG_NOTICE 5
94 #define LWPA_LOG_INFO 6
95 #define LWPA_LOG_DEBUG 7
98 #define LWPA_LOG_PRIMASK 0x07
99 #define LWPA_LOG_PRI(p) ((p)&LWPA_LOG_PRIMASK)
100 #define LWPA_LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
102 #define LWPA_LOG_MASK(pri) (1 << (pri))
103 #define LWPA_LOG_UPTO(pri) \
104 ((1 << ((pri) + 1)) - 1)
106 #define LWPA_LOG_HOSTNAME_MAX_LEN 256
107 #define LWPA_LOG_APP_NAME_MAX_LEN 49
108 #define LWPA_LOG_PROCID_MAX_LEN 129
111 #define LWPA_LOG_MSG_MAX_LEN 480
117 #define LWPA_LOG_TIMESTAMP_LEN (10 + 1 + 12 + 6 + 1 )
120 #define LWPA_SYSLOG_HEADER_MAX_LEN \
121 (5 + 3 + 1 + (LWPA_LOG_TIMESTAMP_LEN - 1) + 1 + \
122 (LWPA_LOG_HOSTNAME_MAX_LEN - 1) + 1 + (LWPA_LOG_APP_NAME_MAX_LEN - 1) + 1 + \
123 (LWPA_LOG_PROCID_MAX_LEN - 1) + 1 + 1 + 1 + 1 + 1 )
126 #define LWPA_SYSLOG_STR_MIN_LEN LWPA_SYSLOG_HEADER_MAX_LEN
128 #define LWPA_HUMAN_LOG_STR_MIN_LEN LWPA_LOG_TIMESTAMP_LEN
132 #define LWPA_SYSLOG_STR_MAX_LEN (LWPA_SYSLOG_HEADER_MAX_LEN + LWPA_LOG_MSG_MAX_LEN)
136 #define LWPA_HUMAN_LOG_STR_MAX_LEN ((LWPA_LOG_TIMESTAMP_LEN - 1) + 1 + LWPA_LOG_MSG_MAX_LEN)
172 typedef void (*
lwpa_log_callback)(
void *context,
const char *syslog_str,
const char *human_str,
const char *raw_str);
229 #define lwpa_setlogmask(logparamsptr, newlogmask) ((logparamsptr)->log_mask = newlogmask)
231 #define lwpa_canlog(logparamsptr, pri) ((LWPA_LOG_MASK(pri) & (logparamsptr)->log_mask) != 0)
241 #pragma __printf_args
246 __attribute__((__format__(__printf__, 6, 7)))
251 #pragma __printf_args
255 __attribute__((__format__(__printf__, 4, 5)))
263 #pragma __printf_args
267 __attribute__((__format__(__printf__, 3, 4)))
void lwpa_sanitize_syslog_params(LwpaSyslogParams *params)
Ensure that the given syslog parameters are compliant with the syslog RFC (modifying them if necessar...
Definition: lwpa_log.c:63
bool lwpa_create_syslog_str(char *buf, size_t buflen, const LwpaLogTimeParams *time, const LwpaSyslogParams *syslog_params, int pri, const char *format,...)
Create a log message with syslog header in the given buffer.
Definition: lwpa_log.c:199
struct LwpaLogParams LwpaLogParams
A set of parameters used for the lwpa_*log() functions.
void lwpa_vlog(const LwpaLogParams *params, int pri, const char *format, va_list args)
Log a message from a library module with the list of format arguments already generated.
Definition: lwpa_log.c:285
struct LwpaLogTimeParams LwpaLogTimeParams
A set of parameters which represent the current local time with millisecond resolution.
void lwpa_log(const LwpaLogParams *params, int pri, const char *format,...)
Log a message from a library module.
Definition: lwpa_log.c:267
void(* lwpa_log_time_fn)(void *context, LwpaLogTimeParams *time_params)
Time callback function.
Definition: lwpa_log.h:181
bool lwpa_validate_log_params(LwpaLogParams *params)
Ensure that the given lwpa_log_params are valid.
Definition: lwpa_log.c:81
lwpa_log_action_t
Which types of log message(s) the lwpa_log() and lwpa_vlog() functions create.
Definition: lwpa_log.h:185
bool lwpa_create_human_log_str(char *buf, size_t buflen, const LwpaLogTimeParams *time, const char *format,...)
Create a log message with a human-readable header in the given buffer.
Definition: lwpa_log.c:248
struct LwpaSyslogParams LwpaSyslogParams
A set of parameters for the syslog header.
#define LWPA_LOG_HOSTNAME_MAX_LEN
Max length of the hostname param.
Definition: lwpa_log.h:105
void(* lwpa_log_callback)(void *context, const char *syslog_str, const char *human_str, const char *raw_str)
Log callback function.
Definition: lwpa_log.h:171
#define LWPA_LOG_APP_NAME_MAX_LEN
Max length of the app_name param.
Definition: lwpa_log.h:106
#define LWPA_LOG_PROCID_MAX_LEN
Max length of the procid param.
Definition: lwpa_log.h:107
@ kLwpaLogCreateBoth
lwpa_log() and lwpa_vlog() create both a syslog message and a human-readable log message and pass the...
Definition: lwpa_log.h:194
@ kLwpaLogCreateHumanReadableLog
lwpa_log() and lwpa_vlog() create a human-readable log message and pass it back in the human_str para...
Definition: lwpa_log.h:191
@ kLwpaLogCreateSyslog
lwpa_log() and lwpa_vlog() create a syslog message and pass it back in the syslog_str parameter of th...
Definition: lwpa_log.h:188
A set of parameters used for the lwpa_*log() functions.
Definition: lwpa_log.h:212
lwpa_log_callback log_fn
A callback function for the finished log string(s).
Definition: lwpa_log.h:216
lwpa_log_action_t action
What should be done when lwpa_*log() is called.
Definition: lwpa_log.h:214
LwpaSyslogParams syslog_params
The syslog header parameters.
Definition: lwpa_log.h:218
int log_mask
A mask value that determines which priority messages can be logged.
Definition: lwpa_log.h:220
void * context
Application context that will be passed back with the log callback function.
Definition: lwpa_log.h:225
lwpa_log_time_fn time_fn
A callback function for lwpa_*log() functions to obtain the time from the application.
Definition: lwpa_log.h:223
A set of parameters which represent the current local time with millisecond resolution.
Definition: lwpa_log.h:139
int utc_offset
The local offset from UTC in minutes.
Definition: lwpa_log.h:155
int hour
Hours since midnight.
Definition: lwpa_log.h:147
int day
Day of the month.
Definition: lwpa_log.h:145
int minute
Minutes past the current hour.
Definition: lwpa_log.h:149
int second
Seconds past the current minute.
Definition: lwpa_log.h:151
int year
Absolute year.
Definition: lwpa_log.h:141
int msec
Milliseconds past the current second.
Definition: lwpa_log.h:153
int month
Month of the year.
Definition: lwpa_log.h:143
A set of parameters for the syslog header.
Definition: lwpa_log.h:199
char procid[LWPA_LOG_PROCID_MAX_LEN]
Syslog PROCID; see RFC 5424 § 6.2.6.
Definition: lwpa_log.h:207
char hostname[LWPA_LOG_HOSTNAME_MAX_LEN]
Syslog HOSTNAME; see RFC 5424 § 6.2.4.
Definition: lwpa_log.h:203
int facility
Syslog Facility; see RFC 5424 § 6.2.1.
Definition: lwpa_log.h:201
char app_name[LWPA_LOG_APP_NAME_MAX_LEN]
Syslog APP-NAME; see RFC 5424 § 6.2.5.
Definition: lwpa_log.h:205