Logging Service Invocation Metadata to a CSV File
Using the StatisticsCSVInterceptor, Membrane API Gateway can log data about service calls into a file. The fields will
be separated by semicolon (;), so that you can import the data into Excel.
Each entry in the log file will contain:
- HTTP status code
- Request time
- The rule that processed the request
- HTTP method used
- Request path as specified by RFC 2616
- Client (see rule key)
- Server, the request target
- Content-Type header of the request
- Content-Length headers of the request
- Content-Type header of the response
- Content-Length headers of the response
- Request/response cycle duration
Configuration
Interceptors can be configured in the proxies.xml file. Interceptors that are registerd with the transport are called for every request, while interceptors that are referenced or defined by a serviceProxy, soapProxy or proxy element only apply to requests that target that proxy.
Logging with the CSV format is handled by the statisticsCSV element. It can be used on a per-proxy basis or globally for all proxies.
Turning On Logging on a Per-Proxy Basis
Per proxy logging can be configured by adding a statisticsCSV element to one of the proxy elements:
<spring:beans xmlns="http://membrane-soa.org/proxies/1/" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd"> <router> <serviceProxy name="predic8.com" port="2000"> <statisticsCSV file="log.csv" /> <target host="membrane-soa.org" port="80" /> </serviceProxy> </router> </spring:beans>
Take also a look at the example located in the examples/logging-csv directory of your membrane distribution.
Turning On Logging Globally
Global logging is configured using the transport element.
Usually, the transport element is missing from the configuration in proxies.xml. This caused the transport to be implicitly included with its default configuration.
But now that we want to modify the transport, we need to include it. The default configuration for the transport can be found in conf/proxies-full-sample.xml:
<transport> <ruleMatching /> <exchangeStore /> <dispatching /> <userFeature /> <httpClient /> </transport>
Add a statisticsCSV element to the transport before its userFeature child and place transport as first child in the router in the conf/proxies.xml file.
<spring:beans xmlns="http://membrane-soa.org/proxies/1/" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd"> <router> <transport> <ruleMatching /> <exchangeStore /> <dispatching /> <statisticsCSV file="log.csv" /> <userFeature /> <httpClient /> </transport> <serviceProxy name="predic8.com" port="2000"> <target host="membrane-soa.org" port="80" /> </serviceProxy> </router> </spring:beans>
Adjust the file attribute, restart the application, and you're all set.