99#include <fcntl.h>
1010#include <uv.h>
1111
12- #define PHP_CASSANDRA_DEFAULT_LOG "php-driver.log"
12+ #define PHP_CASSANDRA_DEFAULT_LOG "cassandra.log"
13+ #define PHP_CASSANDRA_DEFAULT_LOG_LEVEL "ERROR"
1314
1415static uv_once_t log_once = UV_ONCE_INIT ;
1516static char * log_location = NULL ;
@@ -98,7 +99,7 @@ php_cassandra_log(const CassLogMessage* message, void* data)
9899 int fd = -1 ;
99100#ifndef _WIN32
100101 if (!strcmp (log , "syslog" )) {
101- php_syslog (LOG_NOTICE , "php-driver | [%s] %s (%s:%d)" ,
102+ php_syslog (LOG_NOTICE , "cassandra | [%s] %s (%s:%d)" ,
102103 cass_log_level_string (message -> severity ), message -> message ,
103104 message -> file , message -> line );
104105 return ;
@@ -143,7 +144,7 @@ php_cassandra_log(const CassLogMessage* message, void* data)
143144 * logging function are thread-safe.
144145 */
145146
146- fprintf (stderr , "php-driver | [%s] %s (%s:%d)%s" ,
147+ fprintf (stderr , "cassandra | [%s] %s (%s:%d)%s" ,
147148 cass_log_level_string (message -> severity ), message -> message ,
148149 message -> file , message -> line ,
149150 PHP_EOL );
@@ -192,9 +193,24 @@ static PHP_INI_MH(OnUpdateLogLevel)
192193 /* If TSRM is enabled then the last thread to update this wins */
193194
194195 if (new_value ) {
195- long log_level = zend_atol (new_value , new_value_length );
196- if (log_level > CASS_LOG_DISABLED && log_level < CASS_LOG_LAST_ENTRY )
197- cass_log_set_level ((CassLogLevel ) log_level );
196+ if (strcmp (new_value , "CRITICAL" ) == 0 ) {
197+ cass_log_set_level (CASS_LOG_DISABLED );
198+ } else if (strcmp (new_value , "ERROR" ) == 0 ) {
199+ cass_log_set_level (CASS_LOG_ERROR );
200+ } else if (strcmp (new_value , "WARN" ) == 0 ) {
201+ cass_log_set_level (CASS_LOG_WARN );
202+ } else if (strcmp (new_value , "INFO" ) == 0 ) {
203+ cass_log_set_level (CASS_LOG_INFO );
204+ } else if (strcmp (new_value , "DEBUG" ) == 0 ) {
205+ cass_log_set_level (CASS_LOG_DEBUG );
206+ } else if (strcmp (new_value , "TRACE" ) == 0 ) {
207+ cass_log_set_level (CASS_LOG_TRACE );
208+ } else {
209+ php_error_docref (NULL TSRMLS_CC , E_NOTICE ,
210+ "cassandra | Unknown log level '%s', using 'ERROR'" ,
211+ new_value );
212+ cass_log_set_level (CASS_LOG_ERROR );
213+ }
198214 }
199215
200216 return SUCCESS ;
@@ -212,8 +228,11 @@ static PHP_INI_MH(OnUpdateLog)
212228 if (new_value ) {
213229 if (strcmp (new_value , "syslog" ) != 0 ) {
214230 char realpath [MAXPATHLEN + 1 ];
215- if (VCWD_REALPATH (new_value , realpath ))
231+ if (VCWD_REALPATH (new_value , realpath )) {
216232 log_location = strdup (realpath );
233+ } else {
234+ log_location = strdup (new_value );
235+ }
217236 } else {
218237 log_location = strdup (new_value );
219238 }
@@ -224,8 +243,8 @@ static PHP_INI_MH(OnUpdateLog)
224243}
225244
226245PHP_INI_BEGIN ()
227- PHP_INI_ENTRY ("cassandra.log" , PHP_CASSANDRA_DEFAULT_LOG , PHP_INI_ALL , OnUpdateLog )
228- PHP_INI_ENTRY ("cassandra.log_level" , NULL , PHP_INI_ALL , OnUpdateLogLevel )
246+ PHP_INI_ENTRY ("cassandra.log" , PHP_CASSANDRA_DEFAULT_LOG , PHP_INI_ALL , OnUpdateLog )
247+ PHP_INI_ENTRY ("cassandra.log_level" , PHP_CASSANDRA_DEFAULT_LOG_LEVEL , PHP_INI_ALL , OnUpdateLogLevel )
229248PHP_INI_END ()
230249
231250static PHP_GINIT_FUNCTION (cassandra )
@@ -353,6 +372,8 @@ PHP_MINFO_FUNCTION(cassandra)
353372 php_info_print_table_row (2 , "Persistent Sessions" , buf );
354373
355374 php_info_print_table_end ();
375+
376+ DISPLAY_INI_ENTRIES ();
356377}
357378
358379zend_class_entry *
0 commit comments