Debugging/printing in a Hubot script

谁说我不能喝 提交于 2019-12-03 05:44:43

I don't know if this helps but I found a way to inspect objects.

Util = require "util"

module.exports = (robot) ->
  robot.hear /hi robot/i, (msg) ->
    user = robot.brain.usersForFuzzyName(msg.message.user.name)
    msg.send "#{Util.inspect(user)}"

This allowed be to see all the elements of the object so I could figure out what I was doing wrong...

I have discovered the answer myself: console.log MSG in a .coffee Coffeescript source does exactly what I needed.

You can use

robot.logger.info "your log message here"

That will log it just like the other hubot messages get logged.

Found this (coffeescript) snippet somewhere which logs all errors, quite helpful to add to bots in development.

robot.error (err, res) -> robot.logger.error "#{err}\n#{err.stack}" if res? res.reply "#{err}\n#{err.stack}"

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!