From 537012928384b479fd2307b43c90ea768d3d9d39 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 4 Aug 2022 12:33:25 +0530 Subject: [PATCH] feat(nginx): Allow logging settings as site/combined/none --- bench/commands/setup.py | 7 +++++-- bench/config/nginx.py | 3 ++- bench/config/templates/nginx.conf | 11 +++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 6869d034..4aa4a7fc 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -25,13 +25,16 @@ def setup_sudoers(user): @click.command("nginx", help="Generate configuration files for NGINX") +@click.option( + "--logging", default="combined", type=click.Choice(["none", "site", "combined"]) +) @click.option( "--yes", help="Yes to regeneration of nginx config file", default=False, is_flag=True ) -def setup_nginx(yes=False): +def setup_nginx(yes=False, logging="combined"): from bench.config.nginx import make_nginx_conf - make_nginx_conf(bench_path=".", yes=yes) + make_nginx_conf(bench_path=".", yes=yes, logging=logging) @click.command("reload-nginx", help="Checks NGINX config file and reloads service") diff --git a/bench/config/nginx.py b/bench/config/nginx.py index a19f6e56..274c4e70 100644 --- a/bench/config/nginx.py +++ b/bench/config/nginx.py @@ -13,7 +13,7 @@ from bench.bench import Bench from bench.utils import get_bench_name -def make_nginx_conf(bench_path, yes=False): +def make_nginx_conf(bench_path, yes=False, logging=None): conf_path = os.path.join(bench_path, "config", "nginx.conf") if not yes and os.path.exists(conf_path): @@ -43,6 +43,7 @@ def make_nginx_conf(bench_path, yes=False): "allow_rate_limiting": allow_rate_limiting, # for nginx map variable "random_string": "".join(random.choice(string.ascii_lowercase) for i in range(7)), + "logging": logging, } if allow_rate_limiting: diff --git a/bench/config/templates/nginx.conf b/bench/config/templates/nginx.conf index fa09553b..b03f16d2 100644 --- a/bench/config/templates/nginx.conf +++ b/bench/config/templates/nginx.conf @@ -114,11 +114,18 @@ server { {% endfor -%} - # logs in var + {%- if logging == "site" -%} + access_log /var/log/nginx/{{ site_name }}_access.log main; error_log /var/log/nginx/{{ site_name }}_error.log; - + {%- elif logging == "combined" -%} + + access_log /var/log/nginx/access.log main; + error_log /var/log/nginx/error.log; + + {%- endif %} + # optimizations sendfile on; keepalive_timeout 15;