Very simple remote logging.

I thought up a very simple way to get Nginx to handle remote event logging over http using Nginx’s custom log formats. You can format the logs as CSV and use them elsewhere.

Insert the following within http block (outside the server block):

log_format custom '$time_local, $var1, $var2, $var3, $varN';

Add a location into the server block to handle the custom logging:

    location ~/log/(?<var1>([^?]+))/(?<var2>([^?]+))/(?<var3>([^?]+))/(?<varN>([^?]+)) {
        access_log /var/log/nginx/custom.log custom;
        return 200 'ok';
        add_header Content-Type text/plain;

Restart Nginx.

Hit the url from where ever and insert your values in the path:

You should see the csv entry in the custom log file.

Finally, download the log file and import somewhere as a CSV.

I wrote a simple bash script to download the most recent csv and display it in the default spreadsheet software (on a Mac)


# grab the most recent log file
rsync [email protected]:/var/log/nginx/custom.log ./custom.csv

# open it (on a Mac)
open custom.csv

Leave a comment

Your email address will not be published. Required fields are marked *