29 #include "etcpal/common.h"
151 #define ETCPAL_LOG_KERN (0 << 3)
152 #define ETCPAL_LOG_USER (1 << 3)
153 #define ETCPAL_LOG_MAIL (2 << 3)
154 #define ETCPAL_LOG_DAEMON (3 << 3)
155 #define ETCPAL_LOG_AUTH (4 << 3)
156 #define ETCPAL_LOG_SYSLOG (5 << 3)
157 #define ETCPAL_LOG_LPR (6 << 3)
158 #define ETCPAL_LOG_NEWS (7 << 3)
159 #define ETCPAL_LOG_UUCP (8 << 3)
160 #define ETCPAL_LOG_CRON (9 << 3)
161 #define ETCPAL_LOG_AUTHPRIV (10 << 3)
162 #define ETCPAL_LOG_FTP (11 << 3)
164 #define ETCPAL_LOG_LOCAL0 (16 << 3)
165 #define ETCPAL_LOG_LOCAL1 (17 << 3)
166 #define ETCPAL_LOG_LOCAL2 (18 << 3)
167 #define ETCPAL_LOG_LOCAL3 (19 << 3)
168 #define ETCPAL_LOG_LOCAL4 (20 << 3)
169 #define ETCPAL_LOG_LOCAL5 (21 << 3)
170 #define ETCPAL_LOG_LOCAL6 (22 << 3)
171 #define ETCPAL_LOG_LOCAL7 (23 << 3)
176 #define ETCPAL_LOG_NFACILITIES 24
178 #define ETCPAL_LOG_FACMASK 0x03f8
180 #define ETCPAL_LOG_FAC(p) (((p) & ETCPAL_LOG_FACMASK) >> 3)
186 #define ETCPAL_LOG_EMERG 0
187 #define ETCPAL_LOG_ALERT 1
188 #define ETCPAL_LOG_CRIT 2
189 #define ETCPAL_LOG_ERR 3
190 #define ETCPAL_LOG_WARNING 4
191 #define ETCPAL_LOG_NOTICE 5
192 #define ETCPAL_LOG_INFO 6
193 #define ETCPAL_LOG_DEBUG 7
199 #define ETCPAL_LOG_PRIMASK 0x07
201 #define ETCPAL_LOG_PRI(p) ((p) & ETCPAL_LOG_PRIMASK)
202 #define ETCPAL_LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
204 #define ETCPAL_LOG_MASK(pri) (1 << (pri))
205 #define ETCPAL_LOG_UPTO(pri) ((1 << ((pri) + 1)) - 1)
207 #define ETCPAL_LOG_HOSTNAME_MAX_LEN 256u
208 #define ETCPAL_LOG_APP_NAME_MAX_LEN 49u
209 #define ETCPAL_LOG_PROCID_MAX_LEN 129u
212 #define ETCPAL_RAW_LOG_MSG_MAX_LEN 480u
227 #define ETCPAL_LOG_TIMESTAMP_LEN 30u
250 #define ETCPAL_SYSLOG_HEADER_MAX_LEN \
251 (17u + (ETCPAL_LOG_TIMESTAMP_LEN - 1u) + (ETCPAL_LOG_HOSTNAME_MAX_LEN - 1u) + (ETCPAL_LOG_APP_NAME_MAX_LEN - 1u) + \
252 (ETCPAL_LOG_PROCID_MAX_LEN - 1u))
255 #define ETCPAL_SYSLOG_STR_MIN_LEN ETCPAL_SYSLOG_HEADER_MAX_LEN
257 #define ETCPAL_LOG_STR_MIN_LEN (ETCPAL_LOG_TIMESTAMP_LEN + 1u + 6u + 1u )
260 #define ETCPAL_SYSLOG_STR_MAX_LEN (ETCPAL_SYSLOG_HEADER_MAX_LEN + ETCPAL_RAW_LOG_MSG_MAX_LEN)
276 #define ETCPAL_LOG_STR_MAX_LEN (8u + (ETCPAL_LOG_TIMESTAMP_LEN - 1u) + ETCPAL_RAW_LOG_MSG_MAX_LEN)
351 #define ETCPAL_LOG_CREATE_HUMAN_READABLE 0x01
353 #define ETCPAL_LOG_CREATE_SYSLOG 0x02
355 #define ETCPAL_LOG_CREATE_LEGACY_SYSLOG 0x04
379 #define ETCPAL_SYSLOG_PARAMS_INIT \
381 0, {'\0'}, {'\0'}, { '\0' } \
413 #define ETCPAL_LOG_PARAMS_INIT \
415 0, NULL, ETCPAL_SYSLOG_PARAMS_INIT, 0, NULL, NULL \
430 #pragma __printf_args
439 __attribute__((__format__(__printf__, 5, 6)))
451 #pragma __printf_args
461 __attribute__((__format__(__printf__, 6, 7)))
474 #pragma __printf_args
484 __attribute__((__format__(__printf__, 6, 7)))
503 #pragma __printf_args
507 __attribute__((__format__(__printf__, 3, 4)))
etcpal_error_t
A set of error codes that can be returned by library functions.
Definition: error.h:49
#define ETCPAL_LOG_PROCID_MAX_LEN
Max length of the procid param.
Definition: log.h:209
struct EtcPalLogStrings EtcPalLogStrings
The set of log strings passed with a call to an etcpal_log_callback function.
#define ETCPAL_LOG_APP_NAME_MAX_LEN
Max length of the app_name param.
Definition: log.h:208
void etcpal_vlog(const EtcPalLogParams *params, int pri, const char *format, va_list args)
Log a message with the list of format arguments already generated.
Definition: log.c:478
bool etcpal_vcreate_legacy_syslog_str(char *buf, size_t buflen, const EtcPalLogTimestamp *timestamp, const EtcPalSyslogParams *syslog_params, int pri, const char *format, va_list args)
Create a log a message with RFC 3164 syslog header in the given buffer.
Definition: log.c:349
struct EtcPalLogParams EtcPalLogParams
A set of parameters used for the etcpal_*log() functions.
etcpal_error_t etcpal_init_log_handler(const EtcPalLogParams *log_params)
Register the handler for log messages from EtcPal.
Definition: log.c:164
bool etcpal_create_legacy_syslog_str(char *buf, size_t buflen, const EtcPalLogTimestamp *timestamp, const EtcPalSyslogParams *syslog_params, int pri, const char *format,...)
Create a log message with RFC 3164 syslog header in the given buffer.
Definition: log.c:314
struct EtcPalSyslogParams EtcPalSyslogParams
A set of parameters for the syslog header.
void etcpal_sanitize_syslog_params(EtcPalSyslogParams *params)
Ensure that the given syslog parameters are compliant with the syslog RFC (modifying them if necessar...
Definition: log.c:373
bool etcpal_validate_log_timestamp(const EtcPalLogTimestamp *timestamp)
Determine whether the given EtcPalLogTimestamp is valid.
Definition: log.c:417
struct EtcPalLogTimestamp EtcPalLogTimestamp
A set of parameters which represent the current local time with millisecond resolution.
bool etcpal_vcreate_syslog_str(char *buf, size_t buflen, const EtcPalLogTimestamp *timestamp, const EtcPalSyslogParams *syslog_params, int pri, const char *format, va_list args)
Create a log a message with RFC 5424 syslog header in the given buffer.
Definition: log.c:286
bool etcpal_validate_log_params(EtcPalLogParams *params)
Ensure that the given EtcPalLogParams are valid.
Definition: log.c:395
bool etcpal_create_syslog_str(char *buf, size_t buflen, const EtcPalLogTimestamp *timestamp, const EtcPalSyslogParams *syslog_params, int pri, const char *format,...)
Create a log message with RFC 5424 syslog header in the given buffer.
Definition: log.c:251
void etcpal_log(const EtcPalLogParams *params, int pri, const char *format,...)
Log a message.
Definition: log.c:456
bool etcpal_can_log(const EtcPalLogParams *params, int pri)
Determine whether a priority level can be logged given the mask present in the log params.
Definition: log.c:439
bool etcpal_create_log_str(char *buf, size_t buflen, const EtcPalLogTimestamp *timestamp, int pri, const char *format,...)
Create a log message with a human-readable prefix in the given buffer.
Definition: log.c:191
bool etcpal_vcreate_log_str(char *buf, size_t buflen, const EtcPalLogTimestamp *timestamp, int pri, const char *format, va_list args)
Create a log a message with a human-readable prefix in the given buffer.
Definition: log.c:224
void(* EtcPalLogTimeFn)(void *context, EtcPalLogTimestamp *timestamp)
Time callback function.
Definition: log.h:348
void(* EtcPalLogCallback)(void *context, const EtcPalLogStrings *strings)
Log callback function.
Definition: log.h:337
#define ETCPAL_LOG_HOSTNAME_MAX_LEN
Max length of the hostname param.
Definition: log.h:207
A set of parameters used for the etcpal_*log() functions.
Definition: log.h:386
EtcPalSyslogParams syslog_params
The syslog header parameters.
Definition: log.h:392
EtcPalLogCallback log_fn
A callback function for the finished log string(s).
Definition: log.h:390
int action
What should be done when etcpal_log() or etcpal_vlog() is called.
Definition: log.h:388
int log_mask
A mask value that determines which priority messages can be logged.
Definition: log.h:394
EtcPalLogTimeFn time_fn
A callback function for the etcpal_log() and etcpal_vlog() functions to obtain the time from the appl...
Definition: log.h:399
void * context
Application context that will be passed back with the log callback function.
Definition: log.h:401
The set of log strings passed with a call to an etcpal_log_callback function.
Definition: log.h:299
const char * human_readable
Log string formatted for readability per ETC convention.
Definition: log.h:305
const char * syslog
Log string formatted compliant to RFC 5424.
Definition: log.h:301
const char * legacy_syslog
Log string formatted compliant to RFC 3164.
Definition: log.h:303
const char * raw
The original log string that was passed to etcpal_log() or etcpal_vlog().
Definition: log.h:310
int priority
The original log priority that was passed to etcpal_log() or etcpal_vlog().
Definition: log.h:315
A set of parameters which represent the current local time with millisecond resolution.
Definition: log.h:283
int utc_offset
The local offset from UTC in minutes.
Definition: log.h:291
unsigned int day
Day of the month.
Definition: log.h:286
unsigned int second
Seconds past the current minute.
Definition: log.h:289
unsigned int minute
Minutes past the current hour.
Definition: log.h:288
unsigned int month
Month of the year.
Definition: log.h:285
unsigned int year
Absolute year.
Definition: log.h:284
unsigned int hour
Hours since midnight.
Definition: log.h:287
unsigned int msec
Milliseconds past the current second.
Definition: log.h:290
A set of parameters for the syslog header.
Definition: log.h:359
int facility
Syslog Facility; see RFC 5424 § 6.2.1.
Definition: log.h:361
char app_name[ETCPAL_LOG_APP_NAME_MAX_LEN]
Syslog APP-NAME; see RFC 5424 § 6.2.5.
Definition: log.h:365
char procid[ETCPAL_LOG_PROCID_MAX_LEN]
Syslog PROCID; see RFC 5424 § 6.2.6.
Definition: log.h:367
char hostname[ETCPAL_LOG_HOSTNAME_MAX_LEN]
Syslog HOSTNAME; see RFC 5424 § 6.2.4.
Definition: log.h:363