Gradle spring web流量日志

Gradle spring web流量日志,gradle,spring-webflux,logbook,Gradle,Spring Webflux,Logbook,我通过添加依赖项(gradle项目)完成了这项工作 和插件(因为自动配置要求不低于2.4.2启动版本) 它很方便,除了添加依赖项,我无需再做其他事情。但它不可用,因为gitlab上的管道出现故障(我不知道为什么) 是否有任何示例如何使用日志而不依赖日志spring boot webflux autoconfigure来一步一步地记录spring webflux请求/响应? 例如插件(有了它们我就可以了) 谢谢大家! 我解决了我的问题。这里是配置类 package config; import

我通过添加依赖项(gradle项目)完成了这项工作

和插件(因为自动配置要求不低于2.4.2启动版本)

它很方便,除了添加依赖项,我无需再做其他事情。但它不可用,因为gitlab上的管道出现故障(我不知道为什么)

是否有任何示例如何使用日志而不依赖日志spring boot webflux autoconfigure来一步一步地记录spring webflux请求/响应? 例如插件(有了它们我就可以了)


谢谢大家!

我解决了我的问题。这里是配置类

package config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
import org.springframework.boot.web.embedded.netty.NettyServerCustomizer
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.zalando.logbook.Logbook
import org.zalando.logbook.netty.LogbookServerHandler
import reactor.netty.Connection
import reactor.netty.http.server.HttpServer
import reactor.netty.tcp.TcpServer

@Configuration(proxyBeanMethods = false)
class LogbookFluxConfig {

    companion object {
        const val CUSTOMIZER_NAME = "logbookNettyServerCustomizer"
    }

    @Bean
    @ConditionalOnProperty(name = ["logbook.filter.enabled"], havingValue = "true", matchIfMissing = true)
    @ConditionalOnMissingBean(name = [CUSTOMIZER_NAME])
    @ConditionalOnClass(HttpServer::class)
    @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
    fun logbookNettyServerCustomizer(logbook: Logbook?): NettyServerCustomizer {
        return NettyServerCustomizer { httpServer: HttpServer ->
            httpServer.tcpConfiguration { tcpServer: TcpServer ->
                tcpServer.doOnConnection { connection: Connection ->
                    connection.addHandlerLast(LogbookServerHandler(logbook!!))
                }
            }
        }
    }
}
application.yml

logging:
  level:        
    org:
      zalando:
        logbook: TRACE
logbook:
  include: /api/**
  filter.enabled: ${LOGBOOK_FILTER_ENABLED:true}
  format.style: http
  obfuscate.write.category: http.wire-log
  write:
    chunk-size: ${LOGBOOK_CHUNK_SIZE:1000}
    max-body-size: ${LOGBOOK_WRITE_MAX_BODY_SIZE:100000}
    level: ${LOGBOOK_WRITE_LEVEL:INFO}
和依赖关系(部分)

现在我可以继续使用旧版本的spring boot了

plugins {
    id("org.springframework.boot") version "2.2.4.RELEASE"
    id("io.spring.dependency-management") version "1.0.9.RELEASE"
}

但它不可用,因为gitlab上的管道出现故障(我不知道为什么)
我将首先解决这个问题。
package config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
import org.springframework.boot.web.embedded.netty.NettyServerCustomizer
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.zalando.logbook.Logbook
import org.zalando.logbook.netty.LogbookServerHandler
import reactor.netty.Connection
import reactor.netty.http.server.HttpServer
import reactor.netty.tcp.TcpServer

@Configuration(proxyBeanMethods = false)
class LogbookFluxConfig {

    companion object {
        const val CUSTOMIZER_NAME = "logbookNettyServerCustomizer"
    }

    @Bean
    @ConditionalOnProperty(name = ["logbook.filter.enabled"], havingValue = "true", matchIfMissing = true)
    @ConditionalOnMissingBean(name = [CUSTOMIZER_NAME])
    @ConditionalOnClass(HttpServer::class)
    @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
    fun logbookNettyServerCustomizer(logbook: Logbook?): NettyServerCustomizer {
        return NettyServerCustomizer { httpServer: HttpServer ->
            httpServer.tcpConfiguration { tcpServer: TcpServer ->
                tcpServer.doOnConnection { connection: Connection ->
                    connection.addHandlerLast(LogbookServerHandler(logbook!!))
                }
            }
        }
    }
}
logging:
  level:        
    org:
      zalando:
        logbook: TRACE
logbook:
  include: /api/**
  filter.enabled: ${LOGBOOK_FILTER_ENABLED:true}
  format.style: http
  obfuscate.write.category: http.wire-log
  write:
    chunk-size: ${LOGBOOK_CHUNK_SIZE:1000}
    max-body-size: ${LOGBOOK_WRITE_MAX_BODY_SIZE:100000}
    level: ${LOGBOOK_WRITE_LEVEL:INFO}
implementation("org.zalando:logbook-spring-boot-autoconfigure:2.5.0") {
        exclude(group = "javax.servlet", module = "javax.servlet-api")
    }
    implementation("org.zalando:logbook-netty:2.5.0")
plugins {
    id("org.springframework.boot") version "2.2.4.RELEASE"
    id("io.spring.dependency-management") version "1.0.9.RELEASE"
}