To make identifying logs of any kind which are related to a given HTTP request, a unique identifier should be generated and added to the logs.
In sonar.log, it should be added in the "field" after "web", so this:
2016.11.02 18:23:01 TRACE web[][sql] time=0ms | sql=select id, data from notifications order by id asc limit ? | params=1
will become this:
2016.11.02 18:23:01 TRACE web[XXXXXXXXXX][sql] time=0ms | sql=select id, data from notifications order by id asc limit ? | params=1
It will also be possible to display this identifier in "access.log" by adding %reqAttribute{ID} to the pattern.
Obviously, the generation of the unique identifier should be super fast to not create an overhead on each and every HTTP request.