Logging is an essential part of any software. Good logs can be a developers biggest weapon when tracing problems in their code. This is especially true in the web, where issues are usually noticed after they occur, and are hard to recreate without knowing the parameters that caused them; which in a public API, are coming from somewhere outside of the developers control. Although, not every log is the same. It’s important to do logging that records enough information, as sometimes a stack trace is just not enough.
Because of this, an Apinizer gateway is configured to log every interaction by default. The state of each and every request is logged as it’s being served. This way you don’t have to spend time on implementing logging inside your own application. You can use Apinizer’s logs to debug issues, see traffic, and analyze anything from traffic statistics to performance metrics.
If you open the Apinizer Manager, and go to API Analytics > API Logs
, you can access a basic table of request logs. The API Analytics category has many tools to monitor your gateways and APIs, but we’re going to focus on API Logs as it’s the most straightforward tool. API Logs has each request that was processed by your gateways. With it you can see everything there is to know about a request:
- Status: The HTTP code of the response (e.g 404, 200)
- Created Time: When the request arrived
- Gateway: Which gateway it was processed by
- Request Address: The IP address of the client
- Sent Address: The IP/URL Apinizer redirected the request to
- HTTP Method: What HTTP method was used (e.g GET, POST)
- Request Size: Size of the request body in bytes
- Response Size: Size of the response body in bytes
- Total Time: How long the total interaction took
In addition to these, you can view the whole message (headers, parameters, and body) by clicking the magnifier button at the right side of each request. This includes all 4 messages, so not only can you see the exact messages that were received from and sent to the client, but also the messages between Apinizer and the target service.
Configuring API Logs
There may be times where you don’t need logging of entire requests on a gateway. You might have a platform that you believe is stable enough or you might not need some of Apinizer’s statistics. This is very easy to configure on a per-gateway basis. Just head to the configuration page of the gateway you want to edit, and look for green pencil icons to configure logging settings.
- Client to Gateway
- Gateway to Target Application
- Target Application to Gateway
- Gateway to Client
For example, if you have a minimal Apinizer installation that doesn’t do any message transformation, you can turn off a pair of these to reduce duplicates in your logs. As with every gateway operation, you’ll have to redeploy the gateway for your new logging rules to take effect.
Documentation
Apinizer’s Documentation also has many resources about it’s logging capabilities, here is a list of the essential ones: