Skip to content

Commit 8088625

Browse files
committed
Merge pull request nandub#115 from lusis/logging_fix
change to use proper logger
2 parents acb02ce + 24d5723 commit 8088625

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"test": "grunt"
2424
},
2525
"dependencies": {
26-
"irc": "git+https://github.com/nandub/node-irc.git"
26+
"irc": "git+https://github.com/nandub/node-irc.git",
27+
"log": "1.4.0"
2728
},
2829
"devDependencies": {
2930
"grunt": "~0.4.1",

src/irc.coffee

+26-23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# Irc library
55
Irc = require 'irc'
66

7+
Log = require('log')
8+
logger = new Log process.env.HUBOT_LOG_LEVEL or 'info'
9+
710
class IrcBot extends Adapter
811
send: (envelope, strings...) ->
912
# Use @notice if SEND_NOTICE_MODE is set
@@ -12,7 +15,7 @@ class IrcBot extends Adapter
1215
target = @_getTargetFromEnvelope envelope
1316

1417
unless target
15-
return console.log "ERROR: Not sure who to send to. envelope=", envelope
18+
return logger.error "ERROR: Not sure who to send to. envelope=", envelope
1619

1720
for str in strings
1821
@bot.say target, str
@@ -29,7 +32,7 @@ class IrcBot extends Adapter
2932
target = @_getTargetFromEnvelope envelope
3033

3134
unless target
32-
return console.log "ERROR: Not sure who to send to. envelope=", envelope
35+
return logger.error "ERROR: Not sure who to send to. envelope=", envelope
3336

3437
for str in strings
3538
@bot.action target, str
@@ -38,7 +41,7 @@ class IrcBot extends Adapter
3841
target = @_getTargetFromEnvelope envelope
3942

4043
unless target
41-
return console.log "Notice: no target found", envelope
44+
return logger.warn "Notice: no target found", envelope
4245

4346
# Flatten out strings from send
4447
flattened = []
@@ -61,15 +64,15 @@ class IrcBot extends Adapter
6164
join: (channel) ->
6265
self = @
6366
@bot.join channel, () ->
64-
console.log('joined %s', channel)
67+
logger.info('joined %s', channel)
6568

6669
selfUser = self.getUserFromName self.robot.name
6770
self.receive new EnterMessage(selfUser)
6871

6972
part: (channel) ->
7073
self = @
7174
@bot.part channel, () ->
72-
console.log('left %s', channel)
75+
logger.info('left %s', channel)
7376

7477
selfUser = self.getUserFromName self.robot.name
7578
self.receive new LeaveMessage(selfUser)
@@ -199,11 +202,11 @@ class IrcBot extends Adapter
199202

200203
bot.addListener 'notice', (from, to, message) ->
201204
if from in options.ignoreUsers
202-
console.log('Ignoring user: %s', from)
205+
logger.info('Ignoring user: %s', from)
203206
# we'll ignore this message if it's from someone we want to ignore
204207
return
205208

206-
console.log "NOTICE from #{from} to #{to}: #{message}"
209+
logger.info "NOTICE from #{from} to #{to}: #{message}"
207210

208211
user = self.createUser to, from
209212
self.receive new TextMessage(user, message)
@@ -214,49 +217,49 @@ class IrcBot extends Adapter
214217
return
215218

216219
if from in options.ignoreUsers
217-
console.log('Ignoring user: %s', from)
220+
logger.info('Ignoring user: %s', from)
218221
# we'll ignore this message if it's from someone we want to ignore
219222
return
220223

221-
console.log "From #{from} to #{to}: #{message}"
224+
logger.debug "From #{from} to #{to}: #{message}"
222225

223226
user = self.createUser to, from
224227
if user.room
225-
console.log "#{to} <#{from}> #{message}"
228+
logger.info "#{to} <#{from}> #{message}"
226229
else
227230
unless message.indexOf(to) == 0
228231
message = "#{to}: #{message}"
229-
console.log "msg <#{from}> #{message}"
232+
logger.debug "msg <#{from}> #{message}"
230233

231234
self.receive new TextMessage(user, message)
232235

233236
bot.addListener 'action', (from, to, message) ->
234-
console.log " * From #{from} to #{to}: #{message}"
237+
logger.debug " * From #{from} to #{to}: #{message}"
235238

236239
if from in options.ignoreUsers
237-
console.log('Ignoring user: %s', from)
240+
logger.info('Ignoring user: %s', from)
238241
# we'll ignore this message if it's from someone we want to ignore
239242
return
240243

241244
user = self.createUser to, from
242245
if user.room
243-
console.log "#{to} * #{from} #{message}"
246+
logger.debug "#{to} * #{from} #{message}"
244247
else
245-
console.log "msg <#{from}> #{message}"
248+
logger.debug "msg <#{from}> #{message}"
246249

247250
self.receive new TextMessage(user, message)
248251

249252
bot.addListener 'error', (message) ->
250-
console.error('ERROR: %s: %s', message.command, message.args.join(' '))
253+
logger.error('ERROR: %s: %s', message.command, message.args.join(' '))
251254

252255
bot.addListener 'pm', (nick, message) ->
253-
console.log('Got private message from %s: %s', nick, message)
256+
logger.info('Got private message from %s: %s', nick, message)
254257

255258
if process.env.HUBOT_IRC_PRIVATE
256259
return
257260

258261
if nick in options.ignoreUsers
259-
console.log('Ignoring user: %s', nick)
262+
logger.info('Ignoring user: %s', nick)
260263
# we'll ignore this message if it's from someone we want to ignore
261264
return
262265

@@ -267,25 +270,25 @@ class IrcBot extends Adapter
267270
self.receive new TextMessage({reply_to: nick, name: nick}, message)
268271

269272
bot.addListener 'join', (channel, who) ->
270-
console.log('%s has joined %s', who, channel)
273+
logger.info('%s has joined %s', who, channel)
271274
user = self.createUser channel, who
272275
user.room = channel
273276
self.receive new EnterMessage(user)
274277

275278
bot.addListener 'part', (channel, who, reason) ->
276-
console.log('%s has left %s: %s', who, channel, reason)
279+
logger.info('%s has left %s: %s', who, channel, reason)
277280
user = self.createUser '', who
278281
user.room = channel
279282
self.receive new LeaveMessage(user)
280283

281284
bot.addListener 'kick', (channel, who, _by, reason) ->
282-
console.log('%s was kicked from %s by %s: %s', who, channel, _by, reason)
285+
logger.info('%s was kicked from %s by %s: %s', who, channel, _by, reason)
283286

284287
bot.addListener 'invite', (channel, from) ->
285-
console.log('%s invited you to join %s', from, channel)
288+
logger.info('%s invited you to join %s', from, channel)
286289

287290
if from in options.ignoreUsers
288-
console.log('Ignoring user: %s', from)
291+
logger.info('Ignoring user: %s', from)
289292
# we'll ignore this message if it's from someone we want to ignore
290293
return
291294

0 commit comments

Comments
 (0)