From e8d3cd9b26f0b4d660e424f2657f11bbc01eb171 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Wed, 22 Jul 2020 09:28:42 +0200 Subject: refactoring sp_log_* (#340) Co-authored-by: Giovanni Dante Grazioli --- src/sp_utils.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/sp_utils.h') diff --git a/src/sp_utils.h b/src/sp_utils.h index 91a5a20..744bbff 100644 --- a/src/sp_utils.h +++ b/src/sp_utils.h @@ -28,16 +28,25 @@ #define HOOK_FUNCTION_BY_REGEXP(regexp, hook_table, new_function) \ hook_regexp(regexp, SNUFFLEUPAGUS_G(hook_table), new_function) -#define SP_LOG_SIMULATION 0x100000 -#define SP_LOG_DROP 0x200000 +#define SP_TYPE_LOG (0) +#define SP_TYPE_DROP (1) +#define SP_TYPE_SIMULATION (2) + #define SP_LOG_DEBUG E_NOTICE #define SP_LOG_ERROR E_ERROR #define SP_LOG_WARN E_WARNING -#define sp_log_err(feature, ...) sp_log_msg(feature, SP_LOG_ERROR, __VA_ARGS__) -#define sp_log_warn(feature, ...) sp_log_msg(feature, SP_LOG_WARN, __VA_ARGS__) +#define sp_log_msg(feature, level, ...) sp_log_msgf(feature, level, SP_TYPE_LOG, __VA_ARGS__) +#define sp_log_drop(feature, ...) sp_log_msgf(feature, SP_LOG_ERROR, SP_TYPE_DROP, __VA_ARGS__) +#define sp_log_simulation(feature, ...) sp_log_msgf(feature, SP_LOG_WARN, SP_TYPE_SIMULATION, __VA_ARGS__) +#define sp_log_auto(feature, is_simulation, ...) sp_log_msgf(feature, \ + (is_simulation ? SP_LOG_WARN : SP_LOG_ERROR), \ + (is_simulation ? SP_TYPE_SIMULATION : SP_TYPE_DROP), __VA_ARGS__) + +#define sp_log_err(feature, ...) sp_log_msgf(feature, SP_LOG_ERROR, SP_TYPE_LOG, __VA_ARGS__) +#define sp_log_warn(feature, ...) sp_log_msgf(feature, SP_LOG_WARN, SP_TYPE_LOG, __VA_ARGS__) #ifdef SP_DEBUG -#define sp_log_debug(...) sp_log_msg("DEBUG", SP_LOG_DEBUG, __VA_ARGS__) +#define sp_log_debug(...) sp_log_msgf("DEBUG", SP_LOG_DEBUG, SP_TYPE_LOG, __VA_ARGS__) #else #define sp_log_debug(...) #endif @@ -45,7 +54,7 @@ #define GET_SUFFIX(x) (x == 1) ? "st" : ((x == 2) ? "nd" : "th") const char *get_ipaddr(); -void sp_log_msg(char const *restrict feature, int type, +void sp_log_msgf(char const *restrict feature, int level, int type, const char *restrict fmt, ...); int compute_hash(const char *const restrict filename, char *restrict file_hash); const zend_string *sp_zval_to_zend_string(const zval *); -- cgit v1.3