From 6ea4278a512bc9f1f816844222e65a4ea670db8e Mon Sep 17 00:00:00 2001 From: jvoisin Date: Fri, 24 Oct 2025 23:50:18 +0200 Subject: feat(log): add the possibility to log to a file --- src/sp_utils.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/sp_utils.c') diff --git a/src/sp_utils.c b/src/sp_utils.c index 775ff95..41eb638 100644 --- a/src/sp_utils.c +++ b/src/sp_utils.c @@ -43,7 +43,7 @@ void sp_log_msgf(char const* const restrict feature, int level, int type, break; } - switch (SPCFG(log_media)) { + switch (SPCFG(log_media).type) { case SP_LOG_SYSLOG: { const char* error_filename = zend_get_executed_filename(); int syslog_level = (level == E_ERROR) ? LOG_ERR : LOG_INFO; @@ -54,6 +54,20 @@ void sp_log_msgf(char const* const restrict feature, int level, int type, closelog(); break; } + case SP_LOG_FILE: { + FILE* logf = fopen(SPCFG(log_media).path, "a"); + if (!logf) { + zend_error(level, "[snuffleupagus][%s][logging][log] unable to open %s to log", client_ip, + SPCFG(log_media).path); + } else { + int error_lineno = zend_get_executed_lineno(TSRMLS_C); + const char* error_filename = zend_get_executed_filename(); + fprintf(logf, "[snuffleupagus][%s][%s][%s] %s in %s on line %d\n", + client_ip, feature, logtype, msg, error_filename, error_lineno); + fclose(logf); + } + break; + } case SP_LOG_ZEND: default: zend_error(level, "[snuffleupagus][%s][%s][%s] %s", client_ip, feature, -- cgit v1.3