microsoft / mysqlnd_azure

mysqlnd_azure is an extension for mysqlnd which enables redirection functionality.
Other
10 stars 17 forks source link

Add AZURE_LOG() to log plugin runtime information #11

Closed coko156 closed 4 years ago

coko156 commented 4 years ago

Logs for mysqlnd_azure plugin

This patch is added for print some running information of mysqlnd_azure to a local file. Current status: Under developing.

New Added Configuration

mysqlnd_azure.logfilePath

Name mysqlnd_azure.logfilePath
Comment Filename that you want your log writes to.
Type String
Accepted Value String length <= 255, legal filename string
Default mysqlnd_azure_runtime.log
Dynamic NO
Note 1. This variable was inited at PHP Module Init (MINIT) period, and immutable at runtime. a call of ini_set('mysqlnd_azure.logLevel', '$VAL'); would fail.
2. Filename length cannot exceed the file system's restriction(255), otherwise system will use the default filename and throw a warning "Given logfile name too long, redirected to default: mysqlnd_azure_runtime.log"

mysqlnd_azure.logLevel

Name mysqlnd_azure.logLevel
Comment The verbose level of log we generate.
Type Enumeration
Accepted Value [ 0 | 1 | 2 | 3 ]
Default 0 (OFF)
Dynamic Yes
Note 1. When the current mysqlnd_azure.logLevel > 0, change logLevel at runtime will be logged.

Loglevel supported

we support 3 level of logs for user:

[SYSTM] maked log rows for Azure mysqlnd Log Module itself, when current mysqlnd_azure.logLevel > 0, any operation related to log system itself will be logged. For example, if someone call ini_set('mysqlnd_azure.logLevel', '2'); at runtime, there may appear a log like

2020-03-27 09:09:05 [SYSTM] mysqlnd_azure.logLevel changed: 3 -> 2

Level value relationship to level logged

Configuration Example:

You can add to section [mysqlnd_azure] in file php.ini

[mysqlnd_azure]
mysqlnd_azure.enableRedirect = 2
mysqlnd_azure.logfilePath = "test.log"
mysqlnd_azure.logLevel = 3

phpinfo() / php -i

After successfully configured, try php -i, there will be var:val pairs listed below mysqlnd_azure section, like:

mysqlnd_azure

mysqlnd_azure => enableRedirect
enableRedirect => preferred
logfilePath => santotest.log
logLevel => 3

What the logs would be (example)

After turned on the option mentioned before, you will see something like :

2020-03-13 11:00:13 [ERROR] Connection cannot established with given information, please check the server availability, or your parameters given
 2020-03-13 11:00:54 [DEBUG] mysqlnd_azure.c: mysqlnd_azure::connect()
 2020-03-13 11:00:54 [DEBUG] mysqlnd_azure.enableRedirect: PREFERRD
 2020-03-13 11:00:54 [INFO ] SSL not enabled, and mysqlnd_zaure.enableRedirect if PREFERRED, connection will go through gateway.
 2020-03-13 11:00:54 [DEBUG] mysqlnd_azure.c: mysqlnd_azure::connect()
 2020-03-13 11:00:54 [INFO ] No cache found
 2020-03-13 11:00:54 [DBEUG] mysqlnd_azure.c: mysqlnd_azure_data::connect()
 2020-03-13 11:00:54 [DEBUG] Connection Information: host=127.0.0.1 user=santo db=test port=3306 flags=131072 persistent=1 state=0
 2020-03-13 11:00:54 [ERROR] Connection cannot established with given information, please check the server availability, or your parameters given
 2020-03-13 11:00:54 [DEBUG] mysqlnd_azure.c: mysqlnd_azure::connect()
 2020-03-13 11:00:54 [INFO ] No cache found
 2020-03-13 11:00:54 [DBEUG] mysqlnd_azure.c: mysqlnd_azure_data::connect()
 2020-03-13 11:00:54 [DEBUG] Connection Information: host=santo.mysql.database.azure.com user=test@santo db= port=3306 flags=131072 persistent=1 state=0
 2020-03-13 11:00:54 [DEBUG] Classical connection OK, try to get REDIRECTION information
 2020-03-13 11:00:54 [DEBUG] mysqlnd_azure.c: get_redirect_info()
 2020-03-13 11:00:54 [DEBUG] Successfully get redirection information, try to connect with redirection connection
 2020-03-13 11:00:54 [DEBUG] mysqlnd_azure.c: set_redirect_client_options()
 2020-03-13 11:00:55 [DEBUG] Redirect conntion established.
 2020-03-13 11:00:55 [DEBUG] Prepare the context of new connection
 2020-03-13 11:00:55 [DEBUG] mysqlnd_azure.c: mysqlnd_azure::connect()
 2020-03-13 11:00:55 [DEBUG] mysqlnd_azure.enableRedirect: PREFERRD
 2020-03-13 11:00:55 [INFO ] SSL not enabled, and mysqlnd_zaure.enableRedirect if PREFERRED, connection will go through gateway.
msftclas commented 4 years ago

CLA assistant check
All CLA requirements met.