Le jeu. 23 déc. 2021 à 22:53, Christopher Schultz < ch...@christopherschultz.net> a écrit :
> Romain, > > On 12/18/21 14:28, Romain Manni-Bucau wrote: > > I wonder if you would be interested in an access log "function" enabling > to > > make an access log element a valid json string. > > > > Idea is to enable to have access logs patterns producing valid JSON > > whatever the dynamic string content, maybe something like > > > > "key":"jsonEscaped(%r)",.... > > > > or more tomcat style: > > > > "key":"%{json}r)",.... > > If you tried that today, you'd get the value of the request attribute > named "json". I think we need a different syntax. > > The closest thing to this I see in the current configuration is > specifying the date-format of a timestamp like this: > > %{pattern}t where %{...}t gets you the end-of-request timestamp. > > I think it's going to be ugly no matter what we do. > > Maybe instead of putting the escaping in the pattern, we could put the > type of escaping into another attribute like this: > > <Valve className="org.apache.catalina.valves.AccessLogValve" > ... > escaping="json" > pattern="..." /> > > Then, when any %{...}? replacement will be done, it can be JSON-escaped. This has a perf drawback (several %{} dont need it) I'd like to avoid if possible and some %x would need escaping so fear it is not precise enough, no? > Any literal text in the pattern itself is up to the admin; specifically, > it will not have any escaping applied to the pattern text, only the > replacements. > > > What do you think? Is it worth proposing something or is it always > handled > > differently in your opinion (I tend to workaround it today so not 100% > sure > > it would be accepted if I do a PR)? > > Actually, this could easily be done by subclassing AccessLogValve and > overriding AbstractAccessLogValve.escapeAndAppend to provide the proper > escaping. > > I'd be +1 on accepting a JSONAccessLogValve class. > Let me try to PoC it after Xmas, sounds like a good option avoiding the identification issue of enhancing current valve. Thanks Chris > -chris > > > Another location which would benefit from some json encoding > > is org.apache.catalina.valves.JsonErrorReportValve#report since currently > > it produces invalid json depending the message value. > > > > Romain Manni-Bucau > > @rmannibucau <https://twitter.com/rmannibucau> | Blog > > <https://rmannibucau.metawerx.net/> | Old Blog > > <http://rmannibucau.wordpress.com> | Github < > https://github.com/rmannibucau> | > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book > > < > https://www.packtpub.com/application-development/java-ee-8-high-performance > > > > >