summaryrefslogtreecommitdiff
path: root/src/sp_utils.c
diff options
context:
space:
mode:
authorjvoisin2025-10-24 23:50:18 +0200
committerjvoisin2025-10-24 23:55:13 +0200
commit6ea4278a512bc9f1f816844222e65a4ea670db8e (patch)
tree8c645390d3ad5202e3a894f9f6779f4cb590b02e /src/sp_utils.c
parenta167c4d23feb03e6c5b53f41724bbfcb813bf04b (diff)
feat(log): add the possibility to log to a filelog2file
Diffstat (limited to 'src/sp_utils.c')
-rw-r--r--src/sp_utils.c16
1 files changed, 15 insertions, 1 deletions
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,
43 break; 43 break;
44 } 44 }
45 45
46 switch (SPCFG(log_media)) { 46 switch (SPCFG(log_media).type) {
47 case SP_LOG_SYSLOG: { 47 case SP_LOG_SYSLOG: {
48 const char* error_filename = zend_get_executed_filename(); 48 const char* error_filename = zend_get_executed_filename();
49 int syslog_level = (level == E_ERROR) ? LOG_ERR : LOG_INFO; 49 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,
54 closelog(); 54 closelog();
55 break; 55 break;
56 } 56 }
57 case SP_LOG_FILE: {
58 FILE* logf = fopen(SPCFG(log_media).path, "a");
59 if (!logf) {
60 zend_error(level, "[snuffleupagus][%s][logging][log] unable to open %s to log", client_ip,
61 SPCFG(log_media).path);
62 } else {
63 int error_lineno = zend_get_executed_lineno(TSRMLS_C);
64 const char* error_filename = zend_get_executed_filename();
65 fprintf(logf, "[snuffleupagus][%s][%s][%s] %s in %s on line %d\n",
66 client_ip, feature, logtype, msg, error_filename, error_lineno);
67 fclose(logf);
68 }
69 break;
70 }
57 case SP_LOG_ZEND: 71 case SP_LOG_ZEND:
58 default: 72 default:
59 zend_error(level, "[snuffleupagus][%s][%s][%s] %s", client_ip, feature, 73 zend_error(level, "[snuffleupagus][%s][%s][%s] %s", client_ip, feature,