Today I’d show you how to configure the access log format for the application in OpenResty Edge.

Embeded image

Configure access log format on the global config page

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.

Screenshot

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

Screenshot

Go to the Global Config page.

Screenshot

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

Screenshot

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

Screenshot

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.

Screenshot

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

Screenshot

This format records a lot of information, such as remote address IP, request body, upstream status, etc.

Screenshot

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.

Screenshot

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

Screenshot

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

Screenshot

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

Screenshot

Configure access logs for the sample application

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

Screenshot

Go to the applications page.

Screenshot

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

Screenshot

Enter the application.

Screenshot

Go to the settings page.

Screenshot

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

Screenshot

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

Screenshot

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

Screenshot

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

Screenshot

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

Screenshot

Save it.

Screenshot

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

Screenshot

Click on this button.

Screenshot

Ship it!

Screenshot

It is fully synchronized.

Screenshot

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

Embeded video

Embeded video

Embeded video

Our configuration changes do NOT require server reload, restart, or binary upgrade. So it’s very efficient and scalable.

Embeded image

Test access logs

We already have an upstream defined in our earlier tutorial.

Screenshot

This my_backend upstream has a backend server defined already.

Screenshot

And we also have a page rule already defined.

Screenshot

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

Screenshot

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.

Screenshot

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

Screenshot

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

Screenshot

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

Screenshot

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/

Screenshot

Access successful!

Screenshot

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

Screenshot

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

Screenshot

The log file directory is defined in the global config.

Screenshot

And the log file is defined in our application.

Screenshot

Run the command.

Screenshot

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

Screenshot

And remote IP address.

Screenshot

HTTP host.

Screenshot

And request body.

Screenshot

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

Screenshot

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.

Screenshot

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

Screenshot

We can set access log format here.

Screenshot

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.