Technipelago AB

Technipelago Blog Stuff that we learned...


Logging HTTP traffic in Micronaut

Publicerad den 16 nov 2018 av Göran Ehrsson

If you want to see HTTP traffic between your Micronaut HTTP client and servers you can easily enable logging in logback.xml

 

src/main/resources/logback.xml


    
        
            %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
        
    

    
        
    

    


 With this log level you will see both headers and body for HTTP requests and responses. See example below.

14:32:18.251 [nioEventLoopGroup-1-3] DEBUG i.m.http.client.DefaultHttpClient - Sending HTTP Request: POST /login
14:32:18.251 [nioEventLoopGroup-1-3] DEBUG i.m.http.client.DefaultHttpClient - Chosen Server: localhost(9005)
14:32:18.253 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - host: localhost:9005
14:32:18.253 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - connection: close
14:32:18.253 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - content-type: application/json
14:32:18.253 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - content-length: 79
14:32:18.253 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - Request Body
14:32:18.253 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - ----
14:32:18.254 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - {"username":"user","password":"password","identity":"user","secret":"password"}
14:32:18.254 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - ----
14:32:18.676 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - HTTP Client Response Received for Request: POST /login
14:32:18.677 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - Status Code: 200 OK
14:32:18.677 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - Date: Fri, 16 Nov 2018 14:32:18 GMT
14:32:18.677 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - content-type: application/json
14:32:18.677 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - content-length: 567
14:32:18.677 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - connection: close
14:32:18.677 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - Response Body
14:32:18.677 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - ----
14:32:18.678 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - {"username":"user","roles":["ROLE_USER"],"access_token":"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2Vy...","expires_in":3600,"token_type":"Bearer"}
14:32:18.678 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - ----

Tags: micronaut rest


« Tillbaka