Skip to main content

Make Log Collection with HTTP Logger

Estimated reading time: 0 min read

Learning the running status of your API Gateway cluster is necessary in the real world. It's helpful to know if the cluster is healthy or not so that you can take action in time and avoid fatal faults. Logs are one of the most valuable ways to monitor the API Gateway. It also can analyze your API requests (calculate the top N APIs and status codes distribution).

API7 Cloud provides the Log Collection feature to configure "loggers" to collect log messages. With the help of Log Collection, you can transmit logs from Apache APISIX to different log servers ( Apache Kafka, ClickHouse and so on). This guide will show you how to use the Log Collection feature to send Apache APISIX logs to the Loggly service.

important

API7 Cloud doesn't collect your logs itself.

Prepare the Environment

Deploy Apache APISIX

Please refer to How to Deploy Apache APISIX to learn how to deploy Apache APISIX and connect it to API7 Cloud. In this guide, we'll deploy an Apache APISIX instance on Docker.

Configure Log Collection Plan

Let's enter the Log Collection page and click on the Create Log Collection button to create a new Log. Collection Plan.

Log Collection Page Create Log Collection

In this case, we create an HTTP logger, which sends log entries to the Loggly service.

tip
  • If you don't know how to send logs to Loggly HTTP(S) bulk endpoint, please see HTTP Bulk Endpoint for the details.
  • Here, the Logs Concatenation must be "New Line", which is a hard requirement from Loggly.

Create Application and API

We'll create an Application with the following details in this guide.

  • The Application name is loggly-httpbin.
  • The path prefix is /v1.
  • The protocol is HTTP.
  • The HTTP Host is loggly.httpbin.org.
  • The upstream URL is https://httpbin.org.

Besides, we'll create an API inside the loggly-httpbin Application.

  • The API name is json.
  • The path is /json (exact match).
  • Accepted HTTP method is GET.
tip

If you don't know how to configure an Application and API, please refer to the Getting Started guides first

Add Logging Policy

Now let's add the Logging policy to the loggly-httpbin Application.

Add Logging Policy

The Logging policy binds some existing Log Collection Plans to the Application or API.

Send Some Requests

Now let's send some requests.

for ((i=0; i<5; i++)); do
curl http://127.0.0.1:9080/v1/json -H 'Host: loggly.httpbin.org' -v
done

Please wait for a while and log in to the Loggly Console and see if there are five log entries.

Loggly Console

And let's check one of the messages and see if it's expected.

A Log Message in Loggly

As you can see, this log message reflects the actual request we sent, and it contains the response body.

See Also