Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --laconic option to be less verbose but not silent #255

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ Options:
-c, --channel <chan> Single channel guest invite (deprecated) [$SLACK_CHANNEL]
-i, --interval <int> 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 <file> Full URL to a custom CSS file to use on the main page
```

Expand Down Expand Up @@ -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);
```

Expand Down
3 changes: 2 additions & 1 deletion bin/slackin
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function slackin ({
path='/',
channels,
emails,
laconic = false, // jshint ignore:line
silent = false // jshint ignore:line,
}){
// must haves
Expand Down Expand Up @@ -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) => {
Expand Down
16 changes: 11 additions & 5 deletions lib/log.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
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'))
slack.on('retry', () => out('retrying'))

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)` : '')
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion lib/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down