neumino / thinky

JavaScript ORM for RethinkDB
http://justonepixel.com/thinky/
Other
1.12k stars 128 forks source link

Custom log function and set silent: true #626

Closed nodesocket closed 7 years ago

nodesocket commented 7 years ago

How can I define my own log function and set silent: true for the underlying rethinkdbdash connection? In the documentation for rethinkdbdash it says to set the following:

require('rethinkdbdash')({
  silent: true,
  log: function(message) {
    console.log(message);
  }
});

How is this done using thinky?

neumino commented 7 years ago

The same way. Options are directly pass to rethinkdbdash.

nodesocket commented 7 years ago

For others that are trying to get this working, here is the solution I came up with:

const thinky = require('thinky')({
    r: require('rethinkdbdash')(Object.assign(config.rethinkdb, {
        silent: true,
        log: (message) => {
            console.log(`custom logger => ${message}`);
        }
    }))
});

config.rethinkdb is your existing config object that you previously were passing into Thinky.

neumino commented 7 years ago

This is the easiest way to do it:

var thinky = require('thinky')({
  silent: true,
  log: function(message) {
    console.log(message);
  }
});
nodesocket commented 7 years ago

This does work, not sure what I was doing wrong previously. Thanks.

const thinky = require('thinky')(
    _.extend(config.rethinkdb, {
        silent: true,
        log: (message) => {
            console.log(`custom logger => ${message}`);
        }
    })
);