To configure access logs in OpenResty Edge, define a named log format on the Global Config page, then assign it to an application and point it at a log file. Changes push to every gateway server with no reload or restart. The default main format records the remote IP address, HTTP host, and upstream status.

This tutorial walks through configuring the access log format globally, applying it to an application, and verifying the log output on a gateway server.

Configuring the access log format for an application in the OpenResty Edge admin console

Define an access log format in Global Config

As always, let’s go to the OpenResty Edge’s Admin web console. This is our sample deployment of the console. Every user has their local deployment.

The OpenResty Edge admin web console sample deployment

Let’s start by configuring the format of the access log.

Starting to configure the access log format in OpenResty Edge

Go to the Global Config page.

Opening the Global Config page in the OpenResty Edge console

The current configuration belongs to the network partition named “default”.

Global Config for the network partition named default

Let’s jump directly to the section about the log settings.

The log settings section on the Global Config page

Here is the default log file directory. If you want to modify it, you must ensure that the modified directory already exists on all gateway servers.

The default access log file directory in Global Config

Here is the default access log format named “main”.

The default access log format named main

This format records a lot of information, such as the remote address IP, HTTP host, request line, response bytes sent, upstream status, etc.

The main access log format recording remote IP, HTTP host, request line, and upstream status

The “As default” means to set it to the default access log format of this network partition. And in the application, if we don’t change to another log format, the default is to use this.

Setting a format as the default access log format for the network partition

If you want to add a new format, you can click this button.

The button to add a new access log format

In this tutorial we use this existing format “tutorial-example”.

The tutorial-example access log format

It records the request time, remote IP address, HTTP host, and request line.

The tutorial-example format recording request time, remote IP, HTTP host, and request line

Assign the access log format to an application

Now let’s configure this access log format for the application

Configuring the access log format for an application

Go to the applications page.

Opening the applications page in OpenResty Edge

We still use our continuing sample application for the test-edge.com domain.

The sample application for the test-edge.com domain

Enter the application.

Entering the sample application in OpenResty Edge

Go to the settings page.

Opening the application settings page

The network partition named “default” was previously configured for this application.

The application configured for the network partition named default

And the application uses the global config’s default access log format by default.

The application using the Global Config default access log format

We cannot change the access log file when using the default log format.

The access log file locked while using the default log format

Let’s change the log format. We select the “tutorial-example” access log format.

Selecting the tutorial-example access log format for the application

Now we can change the log file. We change it to “example.access.log”.

Changing the application log file to example.access.log

Save it.

Saving the access log format and log file settings

As always, we need to make a new release to push out our changes.

Making a new release to push out the access log changes

Click on this button.

The button to create a new release in OpenResty Edge

Ship it!

Shipping the new release to the gateway clusters

It is fully synchronized.

The release fully synchronized to all gateways

Now our changes have been pushed to all the gateway clusters and servers.

Configuration changes synchronizing to all gateway clusters, start

Configuration changes synchronizing to all gateway clusters, in progress

Configuration changes synchronized across all gateway servers, complete

When you change the access log format, the change syncs to all gateway servers through a binary upgrade — OpenResty’s online hot upgrade, which needs no reload or restart and causes no downtime or dropped connections. So it’s still very efficient and scalable.

Configuration syncing from Edge Admin to each gateway node’s local storage

Test the access log on the gateway server

We already have an upstream defined in our earlier tutorial.

The upstream defined in an earlier OpenResty Edge tutorial

This my_backend upstream has a backend server defined already.

The my_backend upstream with a backend server defined

And we also have a page rule already defined.

The page rule already defined for the application

This page rule sets up a reverse proxy to the upstream we just saw.

The page rule setting up a reverse proxy to the upstream

So when we access the application, there will be upstream content returned.

Now let’s see which gateway server our application belongs to.

Go to the gateway clusters page.

Opening the gateway clusters page

Our application belongs to the network partition named “default”.

The application network partition named default

And there are many gateway clusters belonging to the network partition named “default”.

Gateway clusters belonging to the network partition named default

Let’s select one of them to view the access log messages.

Selecting a gateway cluster to view access log messages

Let’s generate an access log message by accessing the application.

On the terminal, we send a request via curl.

curl -sSI -H 'Host: test-edge.com' http://52.53.251.226/

Sending a request to the application with curl

Access successful!

The curl request to the gateway succeeding

Then, let’s check the access log messages. We log in to the OpenResty Edge gateway server.

Logging in to the OpenResty Edge gateway server

Check the last one access log message in the example.access.log file.

Checking the latest access log message in example.access.log

The log file directory is defined in the global config.

The access log file directory defined in Global Config

And the log file is defined in our application.

The access log file name defined in the application

Run the command.

Running the command to read the access log on the gateway server

We can see the access log message contains the request cost time.

The access log message showing the request cost time

And remote IP address.

The access log message showing the remote IP address

HTTP host.

The access log message showing the HTTP host

And the request line.

The access log message showing the request line

We can see that the access log message matches the access log format “tutorial-example”.

The access log message matching the tutorial-example format

By the way, in addition to configuring access log format for the application in settings page, we can also configure it when we create a new application.

Go back to the applications page.

Returning to the applications page in OpenResty Edge

Click the new application button to see where to set the access log format.

The new application button in OpenResty Edge

We can set access log format here.

The access log format selector on the new application page in OpenResty Edge

Access logs are one part of observability in OpenResty Edge. To inspect failures, see how to view error logs across applications and gateway servers, and how to trace a request with its Request ID.

Frequently asked questions

How do I configure the access log format in OpenResty Edge?

Go to the Global Config page and define (or pick) a named access log format under the log settings. Then open your application’s settings, select that format, and set the log file name. Make a new release to push the change to all gateway servers.

Where does OpenResty Edge store the access log file?

The log file directory is defined in the Global Config, and the log file name is defined per application. In this tutorial the application writes to example.access.log inside the configured log directory on each gateway server.

Can I change the access log format without restarting the gateway?

Yes, with no restart. After you make a new release, the change is pushed to all gateway clusters and servers. Note that changing the access log format triggers a binary upgrade of the gateway — this is OpenResty’s online hot upgrade, which causes no downtime and drops no existing connections, so the gateway keeps serving traffic and never needs a restart. It stays efficient and scalable.

What fields does the default “main” access log format record?

The default format named “main” records a lot of information, including the remote IP address, HTTP host, request line, response bytes sent, request time, and upstream status.

Can I set a different access log format per application?

Yes. Each application can use the network partition’s default format, or select its own — such as the “tutorial-example” format used here, which records the request time, remote IP address, HTTP host, and request line. You can also set the format when you create a new application.

What is OpenResty Edge

OpenResty Edge is our all-in-one gateway software for microservices and distributed traffic architectures. It combines traffic management, private CDN construction, API gateway, security, and more to help you easily build, manage, and protect modern applications. OpenResty Edge delivers industry-leading performance and scalability to meet the demanding needs of high concurrency, high load scenarios. It supports scheduling containerized application traffic such as K8s and manages massive domains, making it easy to meet the needs of large websites and complex applications.

If you like this tutorial, please subscribe to this blog site and/or our YouTube channel. Thank you!

About The Author

Yichun Zhang (Github handle: agentzh), is the original creator of the OpenResty® open-source project and the CEO of OpenResty Inc..

Yichun is one of the earliest advocates and leaders of “open-source technology”. He worked at many internationally renowned tech companies, such as Cloudflare, Yahoo!. He is a pioneer of “edge computing”, “dynamic tracing” and “machine coding”, with over 22 years of programming and 16 years of open source experience. Yichun is well-known in the open-source space as the project leader of OpenResty®, adopted by more than 40 million global website domains.

OpenResty Inc., the enterprise software start-up founded by Yichun in 2017, has customers from some of the biggest companies in the world. Its flagship product, OpenResty XRay, is a non-invasive profiling and troubleshooting tool that significantly enhances and utilizes dynamic tracing technology. And its OpenResty Edge product is a powerful distributed traffic management and private CDN software product.

As an avid open-source contributor, Yichun has contributed more than a million lines of code to numerous open-source projects, including Linux kernel, Nginx, LuaJIT, GDB, SystemTap, LLVM, Perl, etc. He has also authored more than 60 open-source software libraries.