httpAccessLog()

Creates an httpAccess.log file in the log directory and writes a log line for each HTTP request into the file.

Synopsis

int httpAccessLog( bool flag = true);

Parameter

Parameter Description
flag TRUE = httpAccess.log is created.

Return value

The function returns 0 if it was successfully executed and -1 in case of errors.

Error

  • The function is called but an HTTP server instance was not created via the function httpServer().

  • Number of parameters is wrong, meaning > 1.

Description

Creates an httpAccess.log file in the log directory and writes a log line for each HTTP request into the file.

You can alternatively use the Config entry accessLog in the [httpServer] section.

Figure: httpAccess.log file and a log line for the HTTP request - see example below

Example

  1. #uses "CtrlHTTP"
    
    
    main()
    
    
    {
    
    httpServer(false, 8080, 0); //Installs and activates an HTTP server
    
    httpAccessLog(TRUE); /* Creates a httpAccess.log file and writes the netDelete request as incoming connection to the log file. See screenshot above*/
    
    
      httpSetMethodHandler("DELETE", "deleteCB");  //Example of httpSetMethodHandler
    
    
      /* In this example, this is the own client and it sends the HTTP DELETE message */
    
    
      string result;
    
    
      netDelete("http://localhost:8080/firstExample", result);
    
    
      if ( result == "done" )
    
    
        DebugN("resource was deleted");
    
    
    }
    
    
    string deleteCB(string clientIP, string url, int idx)
    
    
    {
    
    
      DebugN("client " + clientIP + " has requested to delete " + url);
    
    
      return "done";
    
    
    }

Assignment

CTRL PlugIn

Availability

CTRL, UI