简体   繁体   English

NodeJS:如何为 @grpc/grpc.js 包启用日志记录

[英]NodeJS: How Is Logging Enabled for the @grpc/grpc.js Package

When creating a GRPC client in NodeJS, if I'm using the grpc package , I can start my program with the GRPC_VERBOSITY set to debug environmental variable.grpc创建 GRPC 客户端时,如果我使用的是grpc,我可以将GRPC_VERBOSITY设置为debug环境变量来启动我的程序。

$ GRPC_VERBOSITY=debug node index.js

and I'll get a ton of information about the network communication that's happening.我将获得大量有关正在发生的网络通信的信息。

However, if I switch out implementations and use the @grpc/grpc-js package, GRPC_VERBOSITY=debug has no effect.但是,如果我切换实现并使用@grpc/grpc-js包,则GRPC_VERBOSITY=debug无效。

I've poked at the underlying typescript that implements @grpc/grpc-js , and I see what look like logging calls .我已经研究了实现@grpc/grpc-js的底层打字稿,我看到了日志调用的样子。

So my question: How can I enable logging when using the @grpc/grpc-js NPM package with NodeJS所以我的问题:如何在@grpc/grpc-js使用@grpc/grpc-js NPM 包时启用日志记录

As can be seen here :可以在这里看到:

if (process.env.GRPC_VERBOSITY) {
  switch (process.env.GRPC_VERBOSITY) {
    case 'DEBUG':
      _logVerbosity = LogVerbosity.DEBUG;
      break;
    case 'INFO':
      _logVerbosity = LogVerbosity.INFO;
      break;
    case 'ERROR':
      _logVerbosity = LogVerbosity.ERROR;
      break;
    default:
    // Ignore any other values
  }
}

Set GRPC_VERBOSITY=DEBUG in uppercaseGRPC_VERBOSITY=DEBUG设置为大写

Also, according to this , you have to set GRPC_TRACE to specify what kind of logs you want to see.另外,根据this ,您必须设置GRPC_TRACE以指定要查看的日志类型。 To see all logs, you can set it to all .要查看所有日志,您可以将其设置为all

So, In your case, the command becomes所以,在你的情况下,命令变成

GRPC_VERBOSITY=DEBUG GRPC_TRACE=all node index.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM