Phantomjs: console.error๊ฐ€ stderr์— ๊ธฐ๋กํ•ฉ๋‹ˆ๊นŒ?

์— ๋งŒ๋“  2014๋…„ 02์›” 08์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: ariya/phantomjs

์•ˆ๋…•ํ•˜์‹ญ๋‹ˆ๊นŒ,

์ตœ์‹  phantomjs 1 9 7์„ ์‚ฌ์šฉํ•˜์—ฌ console.err์„ ์‚ฌ์šฉํ•˜์—ฌ stderr์— ์“ธ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

ํ”„๋ŸฐํŠธ ์—”๋“œ ์Šคํฌ๋ฆฝํŠธ์—์„œ

  throw "some errors";

phantomjs ์Šคํฌ๋ฆฝํŠธ์—์„œ

  page.onConsoleMessage = function(msg, lineNum, sourceId) {
    console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
  };

  page.onError = function(msg, trace) {
    var msgStack = ['ERROR: ' + msg];
    if (trace && trace.length) {
      msgStack.push('TRACE:');
      trace.forEach(function(t) {
        msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : ''));
      });
    }
    console.error(msgStack.join('\n'));
  };

์ด๊ฒƒ์€ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค

 var phantomjsprocess = require('child_process').execFile(phantomjs.path, childArgs);
      phantomjsprocess.stdout
        .on('data', function (data) {
          grunt.verbose.writeln(data.trim());
        })
        // having some difficuties to pass phantomjs errors to stderr, so listens to stdout for errors
        .on('data', function (data) {
          if( data.match(/^(ERROR: )/) ){
            grunt.log.writeln(data.trim());
          }
        });

์ด๊ฒƒ์€ ๊ทธ๋ ‡์ง€ ์•Š๊ฑฐ๋‚˜ ๊ทธ๋ ‡์ง€ ์•Š์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 var phantomjsprocess = require('child_process').execFile(phantomjs.path, childArgs);
      phantomjsprocess.stderr
        .on('data', function (data) {
          grunt.log.writeln(data.trim());
        });

๋‚˜๋Š” ๋ฌธ์ œ # 10232๋ฅผ ์ฝ์—ˆ์ง€๋งŒ ์ •ํ™•ํžˆ ๋‚ด ๋ฌธ์ œ์ด์ง€๋งŒ ์ง€๊ธˆ๊นŒ์ง€๋Š” ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

ํžŒํŠธ๊ฐ€ ์žˆ๋‚˜์š”?

๊ฐ์‚ฌ ํ•ด์š”.

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

์•„ ๋†“์ณค๋„ค์š” ์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค... ์ง€์ ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ ๋ถ„๋“ค์„ ์œ„ํ•ด,
์ด ์Šค๋‹ˆํŽซ์„ phantomjs ๋ž˜ํผ์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

console.error = function () {
    require("system").stderr.write(Array.prototype.join.call(arguments, ' ') + '\n');
};

๊ทธ๋Ÿฐ ๋‹ค์Œ ์ž์‹ ํ”„๋กœ์„ธ์Šค์˜ stderr์„ ๋“ฃ์Šต๋‹ˆ๋‹ค.

phantomJS1.9์—์„œ ํ…Œ์ŠคํŠธ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. 7@์šฐ๋ถ„ํˆฌ13

๋งค๋ ฅ์ฒ˜๋Ÿผ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค!

๋ชจ๋“  3 ๋Œ“๊ธ€

https://github.com/ariya/phantomjs/issues/10150์˜ ๋ณต์ œ๋ณธ์œผ๋กœ ์ข…๋ฃŒ

์•„ ๋†“์ณค๋„ค์š” ์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค... ์ง€์ ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ ๋ถ„๋“ค์„ ์œ„ํ•ด,
์ด ์Šค๋‹ˆํŽซ์„ phantomjs ๋ž˜ํผ์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

console.error = function () {
    require("system").stderr.write(Array.prototype.join.call(arguments, ' ') + '\n');
};

๊ทธ๋Ÿฐ ๋‹ค์Œ ์ž์‹ ํ”„๋กœ์„ธ์Šค์˜ stderr์„ ๋“ฃ์Šต๋‹ˆ๋‹ค.

phantomJS1.9์—์„œ ํ…Œ์ŠคํŠธ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. 7@์šฐ๋ถ„ํˆฌ13

๋งค๋ ฅ์ฒ˜๋Ÿผ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค!

@maboiteaspam ๋‚˜๋Š” ๋‹น์‹ ์˜ ์Šค ๋‹ˆํŽซ์„ ํ›”์ณ์„œ console.error์—์„œ ๊ธฐ๋ณธ์ ์œผ๋กœ stderr์— ๋Œ€ํ•ด https://github.com/sotownsend/BooJS ์— ๋˜์กŒ์Šต๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰