b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen#ifndef EVENT_LOG_H
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen#define EVENT_LOG_H
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainenstruct event_filter;
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen#include "lib-event.h"
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenstruct event_log_params {
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen enum log_type log_type;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen const char *source_filename;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen unsigned int source_linenum;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen};
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenvoid e_error(struct event *event,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen const char *source_filename, unsigned int source_linenum,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen const char *fmt, ...) ATTR_FORMAT(4, 5);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen#define e_error(event, ...) \
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen e_error(event, __FILE__, __LINE__, __VA_ARGS__)
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenvoid e_warning(struct event *event,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen const char *source_filename, unsigned int source_linenum,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen const char *fmt, ...) ATTR_FORMAT(4, 5);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen#define e_warning(event, ...) \
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen e_warning(event, __FILE__, __LINE__, __VA_ARGS__)
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenvoid e_info(struct event *event,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen const char *source_filename, unsigned int source_linenum,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen const char *fmt, ...) ATTR_FORMAT(4, 5);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen#define e_info(event, ...) \
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen e_info(event, __FILE__, __LINE__, __VA_ARGS__)
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenvoid e_debug(struct event *event,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen const char *source_filename, unsigned int source_linenum,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen const char *fmt, ...) ATTR_FORMAT(4, 5);
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen#define e_debug(_event, ...) STMT_START { \
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen struct event *_tmp_event = (_event); \
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen if (event_want_debug(_tmp_event, __FILE__, __LINE__)) \
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen e_debug(_tmp_event, __FILE__, __LINE__, __VA_ARGS__); \
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen else \
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen event_send_abort(_tmp_event); \
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen } STMT_END
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen/* Returns TRUE if debug event should be sent (either logged or sent to
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen stats). */
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainenbool event_want_debug(struct event *event, const char *source_filename,
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen unsigned int source_linenum);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenvoid event_log(struct event *event, const struct event_log_params *params,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen const char *fmt, ...)
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen ATTR_FORMAT(3, 4);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenvoid event_logv(struct event *event, const struct event_log_params *params,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen const char *fmt, va_list args)
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen ATTR_FORMAT(3, 0);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen/* If debugging is forced, the global debug log filter is ignored. Changing
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen this applies only to this event and any child event that is created
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen afterwards. It doesn't apply to existing child events (mainly for
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen performance reasons).
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen Note that it's always recommended to use e.g.:
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen if (set->debug) event_set_forced_debug(event, TRUE); // good
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen instead of
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen event_set_forced_debug(event, set->debug); // bad
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen This is because the event may already have had debugging enabled via the
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen parent event. Forcing it to FALSE is most likely not wanted. */
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenstruct event *event_set_forced_debug(struct event *event, bool force);
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen/* Set the global filter to logging debug events. */
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainenvoid event_set_global_debug_log_filter(struct event_filter *filter);
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen/* Return the current global debug log event filter. */
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainenstruct event_filter *event_get_global_debug_log_filter(void);
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen/* Unset global debug log filter, if one exists. */
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainenvoid event_unset_global_debug_log_filter(void);
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen/* Set the global filter to sending debug events. The debug events are also
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen sent if they match the global debug log filter. */
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainenvoid event_set_global_debug_send_filter(struct event_filter *filter);
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen/* Return the current global debug send event filter. */
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainenstruct event_filter *event_get_global_debug_send_filter(void);
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen/* Unset global debug send filter, if one exists. */
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainenvoid event_unset_global_debug_send_filter(void);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen#endif