remove option using php_error_docref, donot use default file if file len>255, remove AZURE_LOG_SYS
This commit is contained in:
Родитель
e03c2913e9
Коммит
55bdf82655
|
@ -876,9 +876,9 @@ int mysqlnd_azure_apply_resources() {
|
|||
if (MYSQLND_AZURE_G(logOutput) & ALOG_TYPE_FILE) {
|
||||
char *logfilePath = NULL;
|
||||
int logflag = 0;
|
||||
if (ZSTR_LEN(MYSQLND_AZURE_G(logfilePath)) > 155) {
|
||||
logflag = 1;
|
||||
logfilePath = "mysqlnd_azure_runtime.log";
|
||||
if (ZSTR_LEN(MYSQLND_AZURE_G(logfilePath)) > 255) {
|
||||
php_error_docref(NULL, E_WARNING, "[mysqlnd_azure] logOutput=2 but logfilePath %s is invalid. logfilePath string length can not exceed 255.", ZSTR_VAL(MYSQLND_AZURE_G(logfilePath)));
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
logfilePath = ZSTR_VAL(MYSQLND_AZURE_G(logfilePath));
|
||||
|
@ -886,14 +886,10 @@ int mysqlnd_azure_apply_resources() {
|
|||
|
||||
OPEN_LOGFILE(logfilePath);
|
||||
if (!logfile) {
|
||||
php_error_docref(NULL, E_WARNING, "[mysqlnd_azure] Unable to open log file: %s", logfilePath);
|
||||
php_error_docref(NULL, E_WARNING, "[mysqlnd_azure] logOutput=2 but unable to open logfilePath: %s. Please check the configuration of the file is correct.", logfilePath);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (logflag) {
|
||||
php_error_docref(NULL, E_WARNING, "[mysqlnd_azure] Logfile string length exceeds 255, redirected to mysqlnd_azure_runtime.log");
|
||||
AZURE_LOG_SYS("Given logfile name too long, redirected to default: mysqlnd_azure_runtime.log");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ static ZEND_INI_MH(OnUpdateEnableLogLevel) {
|
|||
|
||||
static ZEND_INI_MH(OnUpdateEnableLogOutput) {
|
||||
int tval = atoi(ZSTR_VAL(new_value));
|
||||
if (tval == ALOG_TYPE_PHPERROR || tval == ALOG_TYPE_FILE || tval == ALOG_TYPE_STDERR) {
|
||||
if (tval == ALOG_TYPE_FILE || tval == ALOG_TYPE_STDERR) {
|
||||
MYSQLND_AZURE_G(logOutput) = tval;
|
||||
} else {
|
||||
MYSQLND_AZURE_G(logOutput) = 0;
|
||||
|
@ -103,6 +103,8 @@ static PHP_GINIT_FUNCTION(mysqlnd_azure)
|
|||
mysqlnd_azure_globals->enableRedirect = REDIRECT_PREFERRED;
|
||||
mysqlnd_azure_globals->redirectCache = NULL;
|
||||
mysqlnd_azure_globals->logLevel = 0;
|
||||
mysqlnd_azure_globals->logOutput = 0;
|
||||
mysqlnd_azure_globals->logfilePath = NULL;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
|
35
utils.h
35
utils.h
|
@ -16,9 +16,9 @@ extern FILE *logfile;
|
|||
#define ALOG_LEVEL_DBG 3
|
||||
|
||||
// Azure Log Types
|
||||
#define ALOG_TYPE_PHPERROR (1 << 0)
|
||||
#define ALOG_TYPE_FILE (1 << 1)
|
||||
#define ALOG_TYPE_STDERR (1 << 2)
|
||||
#define ALOG_TYPE_STDERR 1
|
||||
#define ALOG_TYPE_FILE 2
|
||||
|
||||
|
||||
#define OPEN_LOGFILE(filename) \
|
||||
do { \
|
||||
|
@ -41,11 +41,7 @@ extern FILE *logfile;
|
|||
char *levelstr = (level == ALOG_LEVEL_ERR ? "ERROR" : \
|
||||
(level == ALOG_LEVEL_INFO ? "INFO " : "DEBUG")); \
|
||||
strftime(timestr, 20, TIME_FORMAT, localtime(&now)); \
|
||||
if (MYSQLND_AZURE_G(logOutput) & ALOG_TYPE_PHPERROR) { \
|
||||
php_error_docref(NULL, E_WARNING, "[%s] [MYSQLND_AZURE] [%s] " format, \
|
||||
timestr, levelstr, ## __VA_ARGS__); \
|
||||
} \
|
||||
else if ((MYSQLND_AZURE_G(logOutput) & ALOG_TYPE_FILE) && logfile) { \
|
||||
if ((MYSQLND_AZURE_G(logOutput) & ALOG_TYPE_FILE) && logfile) { \
|
||||
fprintf(logfile, "[%s] [MYSQLND_AZURE] [%s] " format "\n", timestr, levelstr, \
|
||||
## __VA_ARGS__); \
|
||||
fflush(logfile); \
|
||||
|
@ -58,28 +54,5 @@ extern FILE *logfile;
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define AZURE_LOG_SYS(format, ...) \
|
||||
do { \
|
||||
if (MYSQLND_AZURE_G(logOutput)) { \
|
||||
time_t now = time(NULL); \
|
||||
char timestr[20]; \
|
||||
strftime(timestr, 20, TIME_FORMAT, localtime(&now)); \
|
||||
if (MYSQLND_AZURE_G(logOutput) & ALOG_TYPE_PHPERROR) { \
|
||||
php_error_docref(NULL, E_WARNING, "[%s] [MYSQLND_AZURE] [SYSTM] " format "%s", \
|
||||
timestr, ## __VA_ARGS__, PHP_EOL); \
|
||||
} \
|
||||
else if ((MYSQLND_AZURE_G(logOutput) & ALOG_TYPE_FILE) && logfile) { \
|
||||
fprintf(logfile, "[%s] [MYSQLND_AZURE] [SYSTM] " format "\n", timestr, \
|
||||
## __VA_ARGS__); \
|
||||
fflush(logfile); \
|
||||
} \
|
||||
else if (MYSQLND_AZURE_G(logOutput) & ALOG_TYPE_STDERR) { \
|
||||
fprintf(stderr, "[%s] [MYSQLND_AZURE] [SYSTM] " format "\n", timestr, \
|
||||
## __VA_ARGS__); \
|
||||
fflush(stderr); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#endif // UTILS_H
|
||||
|
|
Загрузка…
Ссылка в новой задаче