From c62e699844bc291ff9e477211b61311ce5b068de Mon Sep 17 00:00:00 2001 From: Ben Blank Date: Sun, 25 Jun 2017 18:22:16 -0700 Subject: [PATCH] add support for a configurable logger --- README.md | 5 ++++- entities/Defaults.js | 1 + services/IPC.js | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c33f64a..421acf7 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ Set these variables in the `ipc.config` scope to overwrite or set default values silent : false, logInColor : true, logDepth : 5, + logger : console.log, maxConnections : 100, retry : 500, maxRetries : false, @@ -130,6 +131,7 @@ Set these variables in the `ipc.config` scope to overwrite or set default values | silent | turn on/off logging default is false which means logging is on | | logInColor | turn on/off util.inspect colors for ipc.log | | logDepth | set the depth for util.inspect during ipc.log | +| logger | the function which receives the output from ipc.log; should take a single string argument | | maxConnections| this is the max number of connections allowed to a socket. It is currently only being set on Unix Sockets. Other Socket types are using the system defaults. | | retry | this is the time in milliseconds a client will wait before trying to reconnect to a server if the connection is lost. This does not effect UDP sockets since they do not have a client server relationship like Unix Sockets and TCP Sockets. | | maxRetries | if set, it represents the maximum number of retries after each disconnect before giving up and completely killing a specific connection | @@ -148,12 +150,13 @@ These methods are available in the IPC Scope. ipc.log will accept any number of arguments and if `ipc.config.silent` is not set, it will concat them all with a single space ' ' between them and then log them to the console. This is fast because it prevents any concatenation from happening if the ipc.config.silent is set ` true `. That way if you leave your logging in place it should have almost no effect on performance. -The log also uses util.inspect You can control if it should log in color as well as the log depth via ` ipc.config ` +The log also uses util.inspect You can control if it should log in color, the log depth, and the destination via ` ipc.config ` ```javascript ipc.config.logInColor=true; //default ipc.config.logDepth=5; //default + ipc.config.logger=console.log.bind(console); // default ``` diff --git a/entities/Defaults.js b/entities/Defaults.js index 19623d4..ab1a4b2 100644 --- a/entities/Defaults.js +++ b/entities/Defaults.js @@ -34,6 +34,7 @@ class Defaults{ this.silent=false; this.logDepth=5; this.logInColor=true; + this.logger=console.log.bind(console); this.maxConnections=100; this.retry=500; diff --git a/services/IPC.js b/services/IPC.js index e182f86..4f12916 100644 --- a/services/IPC.js +++ b/services/IPC.js @@ -82,7 +82,7 @@ function log(){ ); } - console.log( + this.config.logger( args.join(' ') ); }