clearbit / clearbit-node

Node library for querying the Clearbit business intelligence APIs
https://clearbit.com/docs
MIT License
69 stars 35 forks source link

No option to supress logs #31

Open prashanthr opened 6 years ago

prashanthr commented 6 years ago

When using clearbit to lookup info, a log is added to the console / stdout with the following signature

Making request #1 { protocol: 'https:',
  host: 'company-stream.clearbit.com',
  port: 443,
  path: '/v2/companies/find?domain=google.com',
  method: 'get',
  headers:
   { Accept: '*/*',
     Connection: 'close',
     'User-Agent': 'ClearbitNode/v1.3.3'
...

Currently there is no way to suppress these logs. I believe the underlying root cause is the way clearbit/needle handles the logs. Since this is a forked version of needle, upgrading the version of needle could solve this issue as the new version of needle uses the debug module. Code Reference: node_modules/lib/needle.js line# 25

The best possible option is to provide a way for the clearbit-node client to suppress logs and perform the check in the underlying needle module.

var Client   = require('clearbit').Client
var clearbit = new Client({
   key: 'api_key'
   log: false
})
jonluca commented 5 years ago

👍 Agreed, it's polluting our logs as well.

jonluca commented 5 years ago

I did a little more digging.

The logs are output through a debug function in needle.js, which in turn prints those logs only if !!process.env.DEBUG is true. I don't want to turn debug off for the entire application, but I'm not sure how much clearbit themselves relies on these logs.

I will submit a PR to disable logs soon.

jonluca commented 5 years ago

PR #38

prashanthr commented 5 years ago

Cool! In the meantime, we came up with a hack for this in our application. This may help you.

// Backup debug
const DEBUG_BACKUP = process.env.DEBUG

// Temporarily disable DEBUG if you don't want to see clearbit debug logs
if (!process.env.CLEARBIT_DEBUG) {
  process.env.DEBUG = ''
}

// Import clearbit package
const clearbit = require('clearbit')(YOUR_API_KEY)

// Import debug pacakge in your module
const debug = require('debug')('MY_MODULE')

// Restore DEBUG to it's original config
process.env.DEBUG = DEBUG_BACKUP