Allow Node users to set a custom logger and log verbosity. Defaults to existing core logger
diff --git a/src/node/index.js b/src/node/index.js
index 66664d9..b85cec6 100644
--- a/src/node/index.js
+++ b/src/node/index.js
@@ -46,6 +46,8 @@
var server = require('./src/server.js');
+var common = require('./src/common.js');
+
var Metadata = require('./src/metadata.js');
var grpc = require('./src/grpc_extension');
@@ -123,6 +125,32 @@
};
/**
+ * Sets the logger function for the gRPC module. For debugging purposes, the C
+ * core will log synchronously directly to stdout unless this function is
+ * called. Note: the output format here is intended to be informational, and
+ * is not guaranteed to stay the same in the future.
+ * Logs will be directed to logger.error.
+ * @param {Console} logger A Console-like object.
+ */
+exports.setLogger = function setLogger(logger) {
+ common.logger = logger;
+ grpc.setDefaultLoggerCallback(function(file, line, severity, message) {
+ file = path.basename(file);
+ logger.error(severity + '\t' + file + ':' + line + ']\t' + message);
+ });
+};
+
+/**
+ * Sets the logger verbosity for gRPC module logging. The options are members
+ * of the grpc.logVerbosity map.
+ * @param {Number} verbosity The minimum severity to log
+ */
+exports.setLogVerbosity = function setLogVerbosity(verbosity) {
+ common.logVerbosity = verbosity;
+ grpc.setLogVerbosity(verbosity);
+};
+
+/**
* @see module:src/server.Server
*/
exports.Server = server.Server;
@@ -153,6 +181,11 @@
exports.writeFlags = grpc.writeFlags;
/**
+ * Log verbosity setting name to code number mapping
+ */
+exports.logVerbosity = grpc.logVerbosity;
+
+/**
* Credentials factories
*/
exports.credentials = require('./src/credentials.js');