如何在Meteor的服务器端调试和记录自己的代码? [英] How to debug and log own code on the server side of Meteor?

查看:182
本文介绍了如何在Meteor的服务器端调试和记录自己的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没关系原因不行:我忘了流星复位所以调试器没有机会停止。 Duh!



更多信息:我正在使用Mason Chang的答案中的相关问题,而不是 kill -s USR1 [proc_id ] (我可以看到脚本,但不能在startup()函数中停止)。另外,我正在使用陨石。



我正在尝试调试 Meteor.startup (function())代码在Meteor服务器端(即 / server 下)与node-inspector,我已经读过这个问题,并按照更改 run.js 的答案,但是不知何故,我自己的启动功能的脚本不会显示在Chrome的脚本部分。



我如何看到我的代码并设置断点并停止那些点? BTW,Meteor_debug()不输出任何内容到stdout,stderr或node-inspector浏览器控制台。我也试过console.log()无效。如何在Meteor服务器端启用日志记录?



如果重要,我在 auth 分支。



这里的代码非常简单(/server/bootstrap.js):

  Meteor.startup(function(){
if(Logs.find()。count()=== 0){
var data = [/*...some data ... * / ];
var timestamp =(new Date())。getTime();
Meteor._debug(timestamp:+ timestamp +,data.len:+ data.length);
调试器;
(var i = 0; i data [i] .timestamp = timestamp ++;
var entry_id = Logs.insert(data [ i]);
Meteor._debug(entry_id:+ entry_id);
}
}
});


解决方案

现在我知道如何做到这一点,回答我自己的问题,以便我们可以在这里保留这些信息(详细信息):(这是基于Mason Chang对这个问题。)


  1. 停止流星执行

  2. 编辑陨石安装的 /usr/lib/meteor/app/meteor/run.js (或相应的 run.js HOME //。陨石/流星/流星/流星/ [LONG_HEX_CODE] / app /流星):

    更改行

    [path.join(bundle_path,'main.js'),'--keepalive']



    [' - debug-brk',path.join(bundle_path,'main.js'),'--keepalive']

    // --debug-brk使新线程在第一行断开;

  3. 调试器语句添加为服务器代码中的断点; / li>
  4. 运行 node-inspector& 在服务器终端。 (googlenode-inspector来安装它)。

  5. 运行流星; (这不会有调试器附加,因为没有服务器线程,如果没有客户端窗口打开。)

  6. 刷新客户端浏览器窗口; (启动将在第一行断开的服务器线程,并附加到 node-inspector 。)

  7. 打开浏览器窗口在[SERVER:8080],您的服务器代码在您的 [PROJECT_DIR] /。meteor / local / build中的第一行( main.js );

  8. 点击调试器浏览器窗口上的RUN按钮;根据您的调试器语句的位置,您可能需要在客户端浏览器窗口中执行一些触发操作才能运行到调试器断点(请注意,如果等待太长时间不能进入RUN按钮,则客户端窗口可能会超时,您必须重新刷新。)

  9. 现在,您可以在服务器中进行通常的调试调试器窗口:通过,观察变量,在控制台中执行,查看堆栈等。

编辑:对于登录服务器端,您可以使用Meteor._debug()和console.log(),它们将显示在运行 meteor 的终端中。在客户端,这些日志记录语句将输出到浏览器的开发人员的控制台。工具。


Never mind. The reason this did not work: I forgot to meteor reset so debugger did not get a chance to stop. Duh!

More info: I am using the method in the answer by Mason Chang to the related question, not the kill -s USR1 [proc_id] (where I could see the scripts, but not able to stop in the startup() function.). Also, I am using meteorite.

I am trying to debug the Meteor.startup(function ()) code on Meteor server side (i.e., under /server) with node-inspector, I have read this question, and following the answer to change run.js, but somehow, my own script for the startup function does not show up in the scripts section of Chrome.

How do I see my code here and set break points and stop at those points? BTW, the Meteor_debug() does not output anything to stdout, stderr, or node-inspector browser console. I also tried console.log() with no avail. How to enable logging on Meteor server side?

If it matters, I am on auth branch.

The code here is very simple (/server/bootstrap.js):

Meteor.startup(function () {
 if (Logs.find().count() === 0) {
  var data = [/*...some data...*/];
  var timestamp = (new Date()).getTime();
  Meteor._debug("timestamp: "+timestamp+", data.len: " + data.length);
  debugger;
  for (var i = 0; i < data.length; i++) {
    data[i].timestamp = timestamp++;
    var entry_id = Logs.insert(data[i]);
    Meteor._debug("entry_id: "+ entry_id);
  }
 }
});

解决方案

Now that I know how to do this, I will answer my own question so that we can keep this information (in details) here: (This is based on Mason Chang's answer to this question.)

  1. Stop meteor execution.
  2. Edit /usr/lib/meteor/app/meteor/run.js (or the corresponding run.js installed by meteorite in HOME//.meteorite/meteors/meteor/meteor/[LONG_HEX_CODE]/app/meteor):
    change the line
    [path.join(bundle_path, 'main.js'), '--keepalive']
    to
    ['--debug-brk', path.join(bundle_path, 'main.js'), '--keepalive']
    //--debug-brk makes the new thread break at the first line;
  3. Add debugger statements as breakpoints in your server code;
  4. Run node-inspector & in a server terminal. (google "node-inspector" to install it.)
  5. Run meteor; (this will not have the debugger attached as there's no server thread yet, if you have no client window open.)
  6. Refresh client browser window; (to initiate a server thread that will break at the first line, and be attached to node-inspector.)
  7. Open a browser window at [SERVER:8080], your server code stops at first line (main.js in your [PROJECT_DIR]/.meteor/local/build);
  8. Hit the RUN button on the debugger browser window; depending on where your debugger statements are, you may have to do some triggering actions in client browser window to run to the debugger breakpoints. (Note that if you wait too long to hit the RUN button, your client window may time out, and you have to refresh again.)
  9. Now you can do the usual debugging stuff in server debugger window: step through, watch variables, execute in console, look at the stack, etc.

Edit: For logging on server side, you can use either Meteor._debug() and console.log(), they will show up in the terminal where you run meteor. On client side, these logging statements will output to the console of your browser's dev. tools.

这篇关于如何在Meteor的服务器端调试和记录自己的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆