You are here: Web Services > Consuming Web Services > Logging Request & Response Data

Logging Request & Response Data

When debugging, it's useful to be able to log the request & response data such as headers & body. You can change the logging settings so the following will be logged:

Note that the logs produced on Windows are more detailed than on IBM i due to some limitations of the underlying IBM software implementation.

To change the logging settings, you would first need to set a system-level environment variable (LANSA_XLIB_CONFIG) to point to the path of the configuration file.

You can place the configuration file anywhere (and call it anything) as long as your LANSA system has the required permissions to access the file.

For example, you can call your configuration file lansaxlib.config.json and place that under your Windows temp folder (C:\Windows\Temp), or /tmp on the IBM i.

Place the following configuration data in the file:

{

  "Common":
  {

    "logOutputDir": "c:/Windows/Temp/lansaxlib_logs"

  },
  "HttpRequest":

  {

    "logging":

    {

      "requestHeaders": true,

      "requestBody": true,

      "responseHeaders": true,

      "responseBody": true

    }

  }

}

In the configuration file, you need to specify the output directory (where the logs would be written to), and the logging settings for the HTTP request component. In the example above, logging options for HTTP request are all turned on.

You need to set the environment variable LANSA_XLIB_CONFIG at the system level, both on Windows and IBM i (Windows has the concept of user-level environment variables, and IBM i has job-level environment variables – do not set the environment variable at user-level or job-level). After you set the environment variable, restart your listener and web server.

Alternatively, you can also change the environment variable of the current process only (or job) from your RDML (does not require restarting listener/webserver).

Use the following code:

Define_Com Class(#XPRIM_OSUtil) Name(#OSUtil)

#OSUtil.SetEnvironmentVariable Name('LANSA_XLIB_CONFIG') Value('/tmp/lansaxlib.config.json')

If you have setup the environment variable and your configuration file correctly, you should see the following logs produced under the directory you specified in the configuration file.

Every request will be logged under a different folder (numbered sequentially from 1).

Next: Tutorial 1 - Google Translate API