Debugging/printing in a Hubot script

前端 未结 4 2064
春和景丽
春和景丽 2021-02-07 15:12

I\'m trying to debug an existing Hubot script and in the future write my own, and I need an easy way to debug it or at least print values somewhere (but not to the channel). How

相关标签:
4条回答
  • 2021-02-07 15:53

    You can use

    robot.logger.info "your log message here"
    

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

    0 讨论(0)
  • 2021-02-07 16:04

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

    0 讨论(0)
  • 2021-02-07 16:10

    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...

    0 讨论(0)
  • 2021-02-07 16:11

    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}"

    0 讨论(0)
提交回复
热议问题