简体   繁体   English

在Hubot脚本中调试/打印

[英]Debugging/printing in a Hubot script

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). 我正在尝试调试现有的Hubot脚本,并在将来编写我自己的脚本,我需要一种简单的方法来调试它,或者至少在某处(而不是通道)打印值。 How can I do so? 我怎么能这样做?

Bonus points if this can be done with just using Node in some interactive local mode. 如果可以在某些交互式本地模式下使用Node完成此操作,则可获得奖励积分。 I'm really not sure where to start. 我真的不知道从哪里开始。

All scripts Hubot uses are written in Coffeescript. Hubot使用的所有脚本都是用Coffeescript编写的。

PS I'm using Hubot with Hipchat. PS我正在使用Hubot和Hipchat。

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... 这允许看到对象的所有元素,所以我可以弄清楚我做错了什么...

我自己发现了答案:.coffee Coffeescript源中的console.log MSG正是我所需要的。

You can use 您可以使用

robot.logger.info "your log message here"

That will log it just like the other hubot messages get logged. 这将记录它就像其他hubot消息被记录一样。

发现这个(coffeescript)片段记录了所有错误,非常有助于添加到开发中的机器人。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM