Skip to content

Commit

Permalink
Provide a way to custom log the first events - Fix #334
Browse files Browse the repository at this point in the history
  • Loading branch information
neumino committed May 28, 2017
1 parent 71d512b commit 9fb9556
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ keep a list of updated hosts, default `false`
- `silent`: <boolean> - console.error errors, default `false`
- `servers`: an array of objects `{host: <string>, port: <number>}` representing RethinkDB nodes to connect to
- `optionalRun`: <boolean> - if `false`, yielding a query will not run it, default `true`
- `log`: <function> - will be called with the log events by the pool master

In case of a single instance, you can directly pass `host` and `port` in the top level parameters.

Expand Down Expand Up @@ -271,11 +272,16 @@ r.getPoolMaster().drain();
```

The pool master by default will log all errors/new states on `stderr`. If you do not
want to pollute `stderr`, pass `silent: true` when you import the driver. You can retrieve the
logs by binding a listener for the `log` event on the pool master.
want to pollute `stderr`, pass `silent: true` when you import the driver and
provide your own `log` method.

```js
r.getPoolMaster().on('log', console.log);
r = require('rethinkdbdash')({
silent: true,
log: function(message) {
console.log(message);
}
});
```

##### Advanced details about the pool
Expand Down
3 changes: 3 additions & 0 deletions lib/pool_master.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ function PoolMaster(r, options) {
self._options.buffer = options.buffer || 50;
self._options.max = options.max || 1000;
self._log = helper.createLogger(self, options.silent || false);
if (typeof options.log == 'function') {
self.on('log', options.log);
}
self._draining = false;
self._numConnections = 0;
self._numAvailableConnections = 0;
Expand Down

0 comments on commit 9fb9556

Please sign in to comment.