代码之家  ›  专栏  ›  技术社区  ›  Maddy

需要带Vertx日志说明的GRPC

  •  0
  • Maddy  · 技术社区  · 6 年前

    我使用Kotlin实现了一个带有Vertx的GRPC API,并为调试启用了最好的日志级别。在我的集成测试中,我尝试使用通道将GRPC客户机连接到服务器。

    客户端代码段:

        val clientAsync1 = ctx.async()
                val channel1 = VertxChannelBuilder
                        .forAddress(vertx, "localhost", 10000)
                        .usePlaintext(true)
                        .build()
                val stub1 = ExampleGrpc.newVertxStub(channel1)
    
                val request = builderUtil.buildRequest()
    
                stub1.attemptFriendship(request) { stream ->
                        stream.handler { response ->
    
                        }
                }
    

    我在GRPC Verticle的日志中看到了以下内容:

        [main] 2018-05-24T12:42:27.69+09:00 FINE [io.grpc.internal.ManagedChannelImpl]  [{0}] Exiting idle mode
        [grpc-default-executor-0] 2018-05-24T12:42:27.71+09:00 FINE [io.grpc.internal.ManagedChannelImpl]  [{0}] resolved address: {1}, config={2}
        [main] 2018-05-24T12:42:27.713+09:00 FINE [io.grpc.internal.ManagedChannelImpl]  [{0}] {1} created for {2}
        [main] 2018-05-24T12:42:27.759+09:00 FINE [io.grpc.internal.InternalSubchannel]  [{0}] Created {1} for {2}
        [vert.x-eventloop-thread-0] 2018-05-24T12:42:28.081+09:00 FINE [io.grpc.internal.InternalSubchannel]  [{0}] {1} for {2} is ready
        [vert.x-eventloop-thread-0] 2018-05-24T12:42:35.956+09:00 FINE [io.grpc.internal.ManagedChannelImpl]  [{0}] Created with target {1}
        [vert.x-eventloop-thread-0] 2018-05-24T12:42:35.961+09:00 FINE [io.grpc.internal.ManagedChannelImpl]  [{0}] Exiting idle mode
        [grpc-default-executor-0] 2018-05-24T12:42:35.962+09:00 FINE [io.grpc.internal.ManagedChannelImpl]  [{0}] resolved address: {1}, config={2}
        [grpc-default-executor-0] 2018-05-24T12:42:35.962+09:00 FINE [io.grpc.internal.ManagedChannelImpl]  [{0}] {1} created for {2}
        [grpc-default-executor-0] 2018-05-24T12:42:35.963+09:00 FINE [io.grpc.internal.InternalSubchannel]  [{0}] Created {1} for {2}
        [vert.x-eventloop-thread-0] 2018-05-24T12:42:35.974+09:00 FINE [io.grpc.internal.InternalSubchannel]  [{0}] {1} for {2} is ready
        [vert.x-eventloop-thread-0] 2018-05-24T12:42:46.808+09:00 FINE [io.grpc.internal.ManagedChannelImpl]  [{0}] shutdown() called
        [vert.x-eventloop-thread-0] 2018-05-24T12:42:46.81+09:00 FINE [io.grpc.internal.ManagedChannelImpl]  [{0}] Shutting down
    

    有人能解释一下怎么做吗 [{0}]{1}{2} 意思是?请注意,有几个通道是为完成测试而创建的,响应是流。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Eric Anderson    6 年前

    这个 {0} 格式为 MessageFormat 哪个是默认的格式化程序 java.util.logging . 当调用类似 log(Level level, String msg, Object[] params) , the params 应该和 msg 以形成日志字符串。这是有益的,因为如果不打印日志,则可以避免处理。

    如图所示 java.util.logging.Logger 文档:

    通常,格式化程序使用java.text.messageformat样式格式化来格式化参数,因此,例如格式字符串“0 1”将两个参数格式化为字符串。

    这个 java.util.logging.Formatter 但在您的环境中配置的似乎并没有这样做。