Tech Tip: Logging website errors
PRODUCT: 4D | VERSION: 13.0 | PLATFORM: Mac & Win
Published On: June 8, 2012
When a web browser makes a request that the 4D Web Server does not know how to handle the On Web Connection method gets executed. It can be useful to log these errors to help find broken URLS. Fortuneatly the On Web Connection method is passed parameters that can be useful to log. The following code snippet shows how to create a new record every time an erroneous request is made
CREATE RECORD([Error Log]) [Error Log]url:=$1 [Error Log]header:=$2 [Error Log]clientip:=$3 [Error Log]serverip:=$4 SAVE RECORD([Error Log]) |
The code shown above can be added to the On Web Connection method. The exact location of the code will depend on the implimentation of the On Web Connection method in the website. If the On Web Connection method isn't being used to handle custom URL requests than the code snippet can be put anywhere since On Web Connection will only be executed on an error.
If the On Web Connection method is being used to handle custom URLs, such as a Case statement to direct incomming requests to the proper method, than the code snippet will need to be added to the Case statement. The best way to do this is to use the optional Else command of the Case statement.
Case of : ($1="/Home@") WEB SEND FILE("home.html") : ($1="About@") About : ($1="/Products@)" ShowProducts Else CREATE RECORD([Error Log]) [Error Log]url:=$1 [Error Log]header:=$2 [Error Log]clientip:=$3 [Error Log]serverip:=$4 SAVE RECORD([Error Log]) SendError End case |
This idea can be extended to capture other analytical data on normal requests to the web server.