diff --git a/README.md b/README.md index eb4ea87f..f8e3a397 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,8 @@ Options: -c, --channel Single channel guest invite (deprecated) [$SLACK_CHANNEL] -i, --interval How frequently (ms) to poll Slack [$SLACK_INTERVAL or 5000] -P, --path Path to serve slackin under - -s, --silent Do not print out warns or errors + -l, --laconic Do not print "fetching" or "online 12, total 34 (+56ms)" messages every polling interval, but do print errors, warnings, startup info + -s, --silent Do not print anything, even warnings or errors -c, --css Full URL to a custom CSS file to use on the main page ``` @@ -123,7 +124,7 @@ require('slackin').default({ org: 'your-slack-subdomain', // required path: '/some/path/you/host/slackin/under/', // defaults to '/' channels: 'channel,channel,...', // for single channel mode - silent: false // suppresses warnings + silent: true // suppresses logging }).listen(3000); ``` diff --git a/bin/slackin b/bin/slackin index f6b896b7..af09161e 100755 --- a/bin/slackin +++ b/bin/slackin @@ -10,7 +10,8 @@ args .option(['c', 'channels'], 'One or more comma-separated channel names to allow single-channel guests [$SLACK_CHANNELS]', process.env.SLACK_CHANNELS) .option(['i', 'interval'], 'How frequently (ms) to poll Slack [$SLACK_INTERVAL or 5000]', process.env.SLACK_INTERVAL || 5000) .option(['P', 'path'], 'Path to serve slackin under', '/') - .option(['s', 'silent'], 'Do not print out warns or errors') + .option(['l', 'laconic'], 'Do not print "fetching" or "online 12, total 34 (+56ms)" messages every polling interval, but do print errors, warnings, startup info') + .option(['s', 'silent'], 'Do not print anything, even warnings or errors') .option(['x', 'cors'], 'Enable CORS for all routes') .option(['C', 'coc'], 'Full URL to a CoC that needs to be agreed to') .option(['S', 'css'], 'Full URL to a custom CSS file to use on the main page') diff --git a/lib/index.js b/lib/index.js index d970b6b9..140f5509 100644 --- a/lib/index.js +++ b/lib/index.js @@ -28,6 +28,7 @@ export default function slackin ({ path='/', channels, emails, + laconic = false, // jshint ignore:line silent = false // jshint ignore:line, }){ // must haves @@ -61,7 +62,7 @@ export default function slackin ({ slack.setMaxListeners(Infinity) // capture stats - log(slack, silent) + log(slack, laconic, silent) // middleware for waiting for slack app.use((req, res, next) => { diff --git a/lib/log.js b/lib/log.js index 9e2fde1b..d4aa9c28 100644 --- a/lib/log.js +++ b/lib/log.js @@ -1,11 +1,11 @@ import dbg from 'debug' const debug = dbg('slackin') -export default function log (slack, silent){ +export default function log (slack, laconic, silent){ // keep track of elapsed time let last - out('fetching') + outPoll('fetching') // attach events slack.on('ready', () => out('ready')) @@ -13,14 +13,14 @@ export default function log (slack, silent){ slack.on('fetch', () => { last = new Date - out('fetching') + outPoll('fetching') }) slack.on('data', online) // log online users function online (){ - out('online %d, total %d %s', + outPoll('online %d, total %d %s', slack.users.active, slack.users.total, last ? `(+${new Date - last}ms)` : '') @@ -40,11 +40,17 @@ export default function log (slack, silent){ } function out (...args){ + _out(args, silent) + } + function outPoll (...args){ + _out(args, laconic) + } + function _out (args, doDebug){ if (args) { args[0] = `${new Date} – ${args[0]}` } - if (silent) return debug(...args) + if (doDebug) return debug(...args) console.log(...args) } } diff --git a/lib/slack.js b/lib/slack.js index f648b6eb..cae30579 100644 --- a/lib/slack.js +++ b/lib/slack.js @@ -32,7 +32,7 @@ export default class SlackData extends EventEmitter { .end((err, res) => { let team = res.body.team if (!team) { - throw new Error('Bad Slack response. Make sure the team name and API keys are correct'); + throw new Error('Bad Slack response. Make sure the team name and API keys are correct') } this.org.name = team.name if (!team.icon.image_default) {