Filter Sonar Scanner network inbound/outbound prints

Is there a parameter that Sonar Scanner (CLI) accepts to filter out network inbound & outbound messages like these

I looked at the documentation but I didn’t find any. Searched here

Mar 27, 2020 7:36:08 PM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client out-bound request
1 > POST http://somehost.com
1 > Content-Type: application/x-www-form-urlencoded
1 > Authorization: Basic U1JFQ0FBZG1pbjpTUkVDQUFkbWlu
project_key=projectKey&key=key
Mar 27, 2020 7:36:10 PM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client in-bound response
1 < 400
1 < Server: Apache/2.4.9 (Unix) OpenSSL/1.0.1g
1 < Connection: close
1 < Content-Length: 138
1 < Date: Fri, 27 Mar 2020 16:36:02 GMT
1 < Content-Type: application/json
1 < {"errors":[{"msg":"error message"}]}

It’s not really clear what you’re trying to accomplish (and why), can you explain a bit more?

1 Like

When sonar-scanner CLI runs, it prints tons of INFO network prints to STDOUT which is probably ok when you run it as a standalone cli command. But, when sonar-scanner runs as part of a Jenkins’ pipeline, it makes Jenkins’ output hard to read because of these logs. I don’t want these network prints to be printed to STDOUT.

I can filter them out with grep but I wonder if it can be achieved some parameter similar to sonar.log.level to filter out these network INFO prints

Another thing that I noticed is these network INFO prints are printed to STDERR and not STDOUT which IMHO beats the purpose of STDERR

Hm. It really shows the full inbound/outbound messages you posted in your opening post?

Mar 27, 2020 7:36:10 PM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client in-bound response
1 < 400
1 < Server: Apache/2.4.9 (Unix) OpenSSL/1.0.1g
1 < Connection: close
1 < Content-Length: 138
1 < Date: Fri, 27 Mar 2020 16:36:02 GMT
1 < Content-Type: application/json
1 < {"errors":[{"msg":"error message"}]}

That’s… not standard behavior of the scanner, in regular mode or even with DEBUG logs turned on. Sure, the scanner logs INFO level messages about, broadly, what’s going on during the scan (and when it’s making web calls), but nothing as verbose as what you’ve mentioned.

Here’s the output when I run a scan.

**❯** sonar-scanner -Dsonar.projectKey=test

/Users/colin/Tools/sonar-scanner-4.0.0.1744/bin/sonar-scanner: line 1: #!/bin/sh: No such file or directory
INFO: Scanner configuration file: /Users/colin/Tools/sonar-scanner-4.0.0.1744/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 4.0.0.1744
INFO: Java 11.0.3 Oracle Corporation (64-bit)
INFO: Mac OS X 10.15.4 x86_64
INFO: User cache: /Users/colin/.sonar/cache
INFO: SonarQube server 8.2.0
INFO: Default locale: "en_CH", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=46ms
INFO: Server id: BF41A1F2-AXDzmkBdL_xg6GAzLnww
INFO: User cache: /Users/colin/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=40ms
INFO: Load/download plugins (done) | time=207ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Process project properties (done) | time=1ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=3ms
INFO: Project key: test
INFO: Base dir: /Users/colin/source/newoornotnew
INFO: Working dir: /Users/colin/source/newoornotnew/.scannerwork
INFO: Load project settings for component key: 'test'
INFO: Load project settings for component key: 'test' (done) | time=13ms
INFO: Load project branches
INFO: Load project branches (done) | time=15ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=8ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=1ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=74ms

Maybe there’s some wonky Jenkins configuration, or some options being passed to the JVM running the scanner (the scanner is all Java, so if you have any JAVA_OPTS or similar environment variables, that could affect things).

The only references I can find to logging like this related to SonarQube is when the mibex/sonar-bitbucket-plugin is used. Any chance that comes into play here?

2 Likes

It seems so. We are using CodeCloud which basically the same as BitBucket. The prints looks exactly the same as the ones I am seeing. I don’t have access to SonarQube configuration so I can’t tell for sure.

I applied a workaround to it (running on MacOS)

rm -f sonar_output.txt && sonar-scanner $SONAR_PARAMS 2>>sonar_output.txt | tee -a sonar_output.txt

Printing only stdout to console. Both stdout and stderr are wrote to sonar_output.txt

Thank you for your help @Colin