slomkowski / nginx-config-formatter

nginx config file formatter/beautifier written in Python with no additional dependencies.
Apache License 2.0
380 stars 64 forks source link

log_format #9

Closed denji closed 3 years ago

denji commented 6 years ago

Multiline log_format does not correction the alignment

Input data:

http {
    log_format  main  '.......'
                     '....';
}

Output result

http {
    log_format  main  '.......'
    '....';
}
RickieL commented 6 years ago

I think the output result is the better format.

gethiox commented 5 years ago

Another related issue is that formatter is actually breaking multiline string values with braces. (eg. json) failing test:

def test_multiline_string(self):
    self._check_formatting(
        (
            """http {\n"""
            """    log_format le_json '{"time":"$time_iso8601", '\n"""
            """    '"client_agent":"$client_agent",\n"""
            """    '"user_agent":"$http_user_agent"}';\n"""
            """}\n"""
        ),
        (
            """http {\n"""
            """    log_format le_json '{"time":"$time_iso8601", '\n"""
            """    '"client_agent":"$client_agent",\n"""
            """    '"user_agent":"$http_user_agent"}';\n"""
            """}\n"""
        ),
    )

Modified test output:

----------------------------- Captured stdout call -----------------------------
original:
http {
    log_format le_json '{"time":"$time_iso8601", '
    '"client_agent":"$client_agent",
    '"user_agent":"$http_user_agent"}';
}

formatted:
http {
    log_format le_json ' {
        "time":"$time_iso8601", '
        '"client_agent":"$client_agent",
        '"user_agent":"$http_user_agent"
    }
    ';
}

And this causes three unnecessary newlines on output for each log record.

denji commented 5 years ago

Could we use the official nginxinc/crossplane parser to improve code quality?

slomkowski commented 4 years ago

@denji my goal was to be without any dependencies (just Python), so deployment to various environments is easy (just copy the script). So I won't accept introducing 3rd party libs.