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

4.8k views Asked by At

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_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.

I've poked at the underlying typescript that implements @grpc/grpc-js, and I see what look like logging calls.

So my question: How can I enable logging when using the @grpc/grpc-js NPM package with NodeJS

1

There are 1 answers

4
Ayush Gupta On BEST ANSWER

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 uppercase

Also, according to this, you have to set GRPC_TRACE to specify what kind of logs you want to see. To see all logs, you can set it to all.

So, In your case, the command becomes

GRPC_VERBOSITY=DEBUG GRPC_TRACE=all node index.js