Skip to content

Commit

Permalink
feat(nginx): Allow logging settings as site/combined/none
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed Aug 4, 2022
1 parent 391dcf1 commit 5370129
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 5 additions & 2 deletions bench/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion bench/config/nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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):
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 9 additions & 2 deletions bench/config/templates/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5370129

Please sign in to comment.