29 #include "etcpal/common.h"
140 #define ETCPAL_LOG_KERN (0 << 3)
141 #define ETCPAL_LOG_USER (1 << 3)
142 #define ETCPAL_LOG_MAIL (2 << 3)
143 #define ETCPAL_LOG_DAEMON (3 << 3)
144 #define ETCPAL_LOG_AUTH (4 << 3)
145 #define ETCPAL_LOG_SYSLOG (5 << 3)
146 #define ETCPAL_LOG_LPR (6 << 3)
147 #define ETCPAL_LOG_NEWS (7 << 3)
148 #define ETCPAL_LOG_UUCP (8 << 3)
149 #define ETCPAL_LOG_CRON (9 << 3)
150 #define ETCPAL_LOG_AUTHPRIV (10 << 3)
151 #define ETCPAL_LOG_FTP (11 << 3)
153 #define ETCPAL_LOG_LOCAL0 (16 << 3)
154 #define ETCPAL_LOG_LOCAL1 (17 << 3)
155 #define ETCPAL_LOG_LOCAL2 (18 << 3)
156 #define ETCPAL_LOG_LOCAL3 (19 << 3)
157 #define ETCPAL_LOG_LOCAL4 (20 << 3)
158 #define ETCPAL_LOG_LOCAL5 (21 << 3)
159 #define ETCPAL_LOG_LOCAL6 (22 << 3)
160 #define ETCPAL_LOG_LOCAL7 (23 << 3)
165 #define ETCPAL_LOG_NFACILITIES 24
167 #define ETCPAL_LOG_FACMASK 0x03f8
169 #define ETCPAL_LOG_FAC(p) (((p) & ETCPAL_LOG_FACMASK) >> 3)
175 #define ETCPAL_LOG_EMERG 0
176 #define ETCPAL_LOG_ALERT 1
177 #define ETCPAL_LOG_CRIT 2
178 #define ETCPAL_LOG_ERR 3
179 #define ETCPAL_LOG_WARNING 4
180 #define ETCPAL_LOG_NOTICE 5
181 #define ETCPAL_LOG_INFO 6
182 #define ETCPAL_LOG_DEBUG 7
188 #define ETCPAL_LOG_PRIMASK 0x07
190 #define ETCPAL_LOG_PRI(p) ((p) & ETCPAL_LOG_PRIMASK)
191 #define ETCPAL_LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
193 #define ETCPAL_LOG_MASK(pri) (1 << (pri))
194 #define ETCPAL_LOG_UPTO(pri) ((1 << ((pri) + 1)) - 1)
196 #define ETCPAL_LOG_HOSTNAME_MAX_LEN 256u
197 #define ETCPAL_LOG_APP_NAME_MAX_LEN 49u
198 #define ETCPAL_LOG_PROCID_MAX_LEN 129u
201 #define ETCPAL_RAW_LOG_MSG_MAX_LEN 480u
216 #define ETCPAL_LOG_TIMESTAMP_LEN 30u
239 #define ETCPAL_SYSLOG_HEADER_MAX_LEN \
240 (17u + (ETCPAL_LOG_TIMESTAMP_LEN - 1u) + (ETCPAL_LOG_HOSTNAME_MAX_LEN - 1u) + (ETCPAL_LOG_APP_NAME_MAX_LEN - 1u) + \
241 (ETCPAL_LOG_PROCID_MAX_LEN - 1u))
244 #define ETCPAL_SYSLOG_STR_MIN_LEN ETCPAL_SYSLOG_HEADER_MAX_LEN
246 #define ETCPAL_LOG_STR_MIN_LEN (ETCPAL_LOG_TIMESTAMP_LEN + 1u + 6u + 1u )
249 #define ETCPAL_SYSLOG_STR_MAX_LEN (ETCPAL_SYSLOG_HEADER_MAX_LEN + ETCPAL_RAW_LOG_MSG_MAX_LEN)
265 #define ETCPAL_LOG_STR_MAX_LEN (8u + (ETCPAL_LOG_TIMESTAMP_LEN - 1u) + ETCPAL_RAW_LOG_MSG_MAX_LEN)
340 #define ETCPAL_LOG_CREATE_HUMAN_READABLE 0x01
342 #define ETCPAL_LOG_CREATE_SYSLOG 0x02
344 #define ETCPAL_LOG_CREATE_LEGACY_SYSLOG 0x04
368 #define ETCPAL_SYSLOG_PARAMS_INIT \
370 0, {'\0'}, {'\0'}, { '\0' } \
402 #define ETCPAL_LOG_PARAMS_INIT \
404 0, NULL, ETCPAL_SYSLOG_PARAMS_INIT, 0, NULL, NULL \
417 #pragma __printf_args
426 __attribute__((__format__(__printf__, 5, 6)))
438 #pragma __printf_args
448 __attribute__((__format__(__printf__, 6, 7)))
461 #pragma __printf_args
471 __attribute__((__format__(__printf__, 6, 7)))
490 #pragma __printf_args
494 __attribute__((__format__(__printf__, 3, 4)))
#define ETCPAL_LOG_PROCID_MAX_LEN
Max length of the procid param.
Definition: log.h:198
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:197
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:424
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:307
struct EtcPalLogParams EtcPalLogParams
A set of parameters used for the etcpal_*log() functions.
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:275
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:328
bool etcpal_validate_log_timestamp(const EtcPalLogTimestamp *timestamp)
Determine whether the given EtcPalLogTimestamp is valid.
Definition: log.c:369
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:250
bool etcpal_validate_log_params(EtcPalLogParams *params)
Ensure that the given EtcPalLogParams are valid.
Definition: log.c:347
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:218
void etcpal_log(const EtcPalLogParams *params, int pri, const char *format,...)
Log a message.
Definition: log.c:405
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:388
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:164
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:194
void(* EtcPalLogTimeFn)(void *context, EtcPalLogTimestamp *timestamp)
Time callback function.
Definition: log.h:337
void(* EtcPalLogCallback)(void *context, const EtcPalLogStrings *strings)
Log callback function.
Definition: log.h:326
#define ETCPAL_LOG_HOSTNAME_MAX_LEN
Max length of the hostname param.
Definition: log.h:196
A set of parameters used for the etcpal_*log() functions.
Definition: log.h:375
EtcPalSyslogParams syslog_params
The syslog header parameters.
Definition: log.h:381
EtcPalLogCallback log_fn
A callback function for the finished log string(s).
Definition: log.h:379
int action
What should be done when etcpal_log() or etcpal_vlog() is called.
Definition: log.h:377
int log_mask
A mask value that determines which priority messages can be logged.
Definition: log.h:383
EtcPalLogTimeFn time_fn
A callback function for the etcpal_log() and etcpal_vlog() functions to obtain the time from the appl...
Definition: log.h:388
void * context
Application context that will be passed back with the log callback function.
Definition: log.h:390
The set of log strings passed with a call to an etcpal_log_callback function.
Definition: log.h:288
const char * human_readable
Log string formatted for readability per ETC convention.
Definition: log.h:294
const char * syslog
Log string formatted compliant to RFC 5424.
Definition: log.h:290
const char * legacy_syslog
Log string formatted compliant to RFC 3164.
Definition: log.h:292
const char * raw
The original log string that was passed to etcpal_log() or etcpal_vlog().
Definition: log.h:299
int priority
The original log priority that was passed to etcpal_log() or etcpal_vlog().
Definition: log.h:304
A set of parameters which represent the current local time with millisecond resolution.
Definition: log.h:272
int utc_offset
The local offset from UTC in minutes.
Definition: log.h:280
unsigned int day
Day of the month.
Definition: log.h:275
unsigned int second
Seconds past the current minute.
Definition: log.h:278
unsigned int minute
Minutes past the current hour.
Definition: log.h:277
unsigned int month
Month of the year.
Definition: log.h:274
unsigned int year
Absolute year.
Definition: log.h:273
unsigned int hour
Hours since midnight.
Definition: log.h:276
unsigned int msec
Milliseconds past the current second.
Definition: log.h:279
A set of parameters for the syslog header.
Definition: log.h:348
int facility
Syslog Facility; see RFC 5424 § 6.2.1.
Definition: log.h:350
char app_name[ETCPAL_LOG_APP_NAME_MAX_LEN]
Syslog APP-NAME; see RFC 5424 § 6.2.5.
Definition: log.h:354
char procid[ETCPAL_LOG_PROCID_MAX_LEN]
Syslog PROCID; see RFC 5424 § 6.2.6.
Definition: log.h:356
char hostname[ETCPAL_LOG_HOSTNAME_MAX_LEN]
Syslog HOSTNAME; see RFC 5424 § 6.2.4.
Definition: log.h:352