Re: How can I remove backslash when log format use escape=json
you can try escape=none Posted at Nginx Forum: https://forum.nginx.org/read.php?2,281634,283081#msg-283081 ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx
Re: How can I remove backslash when log format use escape=json
I see, really thanks to your advice. Posted at Nginx Forum: https://forum.nginx.org/read.php?2,281635,281642#msg-281642 ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx
Re: How can I remove backslash when log format use escape=json
Hello! On Thu, Oct 18, 2018 at 09:29:31AM -0400, kimown wrote: > Hi, I want to log my entire request_body, but access.log contains some > strange backslash, how can I remove these backslash before doube quote? > > Here is my nginx.conf, > ``` > log_format main escape=json '$request_body'; > > access_log logs/access.log main; > ``` > > This is my request code: > ``` > fetch('http://localhost:8080/njs',{ > method:'POST', > body:JSON.stringify({ > text:'message with backslash' > }) > }).then(res=>res.json()).then((res)=>{ > console.info(res) > }) > ``` > > And access.log > ``` > {\"text\":\"message with backslash\"} > ``` > > But I think it should be > ``` > {"text":"message with backslash"} > ``` With "escape=json", nginx will escape variables to be usable in JSON structures, so you will be able to use them in log format with JSON formatting, e.g.: log_format main escape=json '{ "body": "$request_body" }'; If you want nginx to do not escape anything in your logs, you can use "escape=none". Note though that without escaping you completely depend on data the variable contain - in particular, in your case a malicious client will be able to supply arbitrary data, including multiple log entries or broken records. -- Maxim Dounin http://mdounin.ru/ ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx
How can I remove backslash when log format use escape=json
Hi, I want to log my entire request_body, but access.log contains some strange backslash, how can I remove these backslash before doube quote? Here is my nginx.conf, ``` log_format main escape=json '$request_body'; access_log logs/access.log main; ``` This is my request code: ``` fetch('http://localhost:8080/njs',{ method:'POST', body:JSON.stringify({ text:'message with backslash' }) }).then(res=>res.json()).then((res)=>{ console.info(res) }) ``` And access.log ``` {\"text\":\"message with backslash\"} ``` But I think it should be ``` {"text":"message with backslash"} ``` Posted at Nginx Forum: https://forum.nginx.org/read.php?2,281634,281634#msg-281634 ___ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx