How to off auto escaping (backslash) double quote when i log with AccessLogValve of Tomcat8

176 Views Asked by At

I have to make logs using AccessLogValve of tomcat8. The logs include double quote.

Tomcat server.xml below

...
<Engine name="Catalina" defaultHost="mypage.com">
    <Host name="mypage.com" appBase="/home1/irteam/mypage"
            workDir="work" unpackWARs="false" deployOnStartup="false"
            autoDeploy="false">

        <Valve className="org.apache.catalina.valves.AccessLogValve"
               directory="/home1/irteam/apps/tomcat/logs"
               prefix="accesslog."
               resolveHosts="false"
               fileDateFormat="yyMMdd"
               pattern="%{timestamp}r, &quot;data&quot;:%{request_data}r"
               requestAttributesEnabled="true"
               encoding="utf-8" />

...

log example below

20230224160000, "data":[{\"code\":\"retry_num\",\"count\":1},{\"code\":\"visit_num\",\"count\":1}]

Although i passed data without escape symble, AccessLogValve make automatically escape symbol (backslash) for double quote in passed data (request, header, session ...). I found documentation explained to adding function of auto escaping for double quote. https://tomcat.apache.org/tomcat-8.5-doc/config/valve.html

I have to make log with double quote. Can I off auto escaping for double quote?

I tried below about passed data (request, header, session...) in java code

  • replace("\\", "")
  • replace(""", """)
  • Using replace function in java code is meaningless, because making escape symbol is occured in AccessLogValve of Tomcat.
0

There are 0 best solutions below