Remove phantom.log, just use the de-facto console.log for logging.

1.0
Ariya Hidayat 2010-12-31 20:10:34 -08:00
parent a2bec750cd
commit 24d433ea13
16 changed files with 49 additions and 47 deletions

View File

@ -1,8 +1,8 @@
if (phantom.arguments.length === 0) {
phantom.log('Try to pass some arguments when invoking this script!');
console.log('Try to pass some arguments when invoking this script!');
} else {
phantom.arguments.forEach(function (arg, i) {
phantom.log(i + ': ' + arg);
console.log(i + ': ' + arg);
});
}
phantom.exit();

View File

@ -1,8 +1,8 @@
var t = 10;
while (t > 0) {
phantom.log(t);
console.log(t);
phantom.sleep(1000);
t = t - 1;
}
phantom.log('BLAST OFF');
console.log('BLAST OFF');
phantom.exit();

View File

@ -3,8 +3,8 @@
if (phantom.storage.length === 0) {
var origin, dest;
if (phantom.arguments.length < 2) {
phantom.log('Usage: direction.js origin destination');
phantom.log('Example: direction.js "San Diego" "Palo Alto"');
console.log('Usage: direction.js origin destination');
console.log('Example: direction.js "San Diego" "Palo Alto"');
phantom.exit(1);
}
origin = phantom.arguments[0];
@ -14,13 +14,13 @@ if (phantom.storage.length === 0) {
'&destination=' + dest + '&units=imperial&mode=driving&sensor=false'));
} else {
if (phantom.loadStatus === 'fail') {
phantom.log('Unable to access network');
console.log('Unable to access network');
phantom.exit(1);
}
direction = x2j(phantom.content);
if (typeof direction == 'undefined') {
phantom.log('No data available for ' + phantom.storage);
console.log('No data available for ' + phantom.storage);
phantom.exit(1);
}
@ -30,11 +30,11 @@ if (phantom.storage.length === 0) {
ins = ins.replace(/\&lt;/ig, '<').replace(/\&gt;/ig, '>');
ins = ins.replace(/\<div/ig, '\n<div');
ins = ins.replace(/<.*?>/g, '');
phantom.log(ins + ' (' + step.distance.text + ')');
console.log(ins + ' (' + step.distance.text + ')');
});
phantom.log('');
phantom.log(route.copyrights);
console.log('');
console.log(route.copyrights);
phantom.exit();
}

View File

@ -1,6 +1,6 @@
var fibs = [0, 1];
var ticker = window.setInterval(function () {
phantom.log(fibs[fibs.length - 1]);
console.log(fibs[fibs.length - 1]);
fibs.push(fibs[fibs.length - 1] + fibs[fibs.length - 2]);
if (fibs.length > 10) {
window.clearInterval(ticker);

View File

@ -1,2 +1,2 @@
phantom.log('Hello, world!');
console.log('Hello, world!');
phantom.exit();

View File

@ -4,8 +4,8 @@ cb = function (data) {
var loc = data.city;
if (data.region_name.length > 0)
loc = loc + ', ' + data.region_name;
phantom.log('IP address: ' + data.ip);
phantom.log('Estimated location: ' + loc);
console.log('IP address: ' + data.ip);
console.log('Estimated location: ' + loc);
phantom.exit();
};

View File

@ -1,20 +1,20 @@
if (phantom.storage.length === 0) {
if (phantom.arguments.length === 0) {
phantom.log('Usage: loadspeed.js <some URL>');
console.log('Usage: loadspeed.js <some URL>');
phantom.exit();
} else {
var address = phantom.arguments[0];
phantom.storage = Date.now().toString();
phantom.log('Loading ' + address);
console.log('Loading ' + address);
phantom.open(address);
}
} else {
var elapsed = Date.now() - new Date().setTime(phantom.storage);
if (phantom.loadStatus === 'success') {
phantom.log('Page title is ' + document.title);
phantom.log('Loading time ' + elapsed + ' msec');
console.log('Page title is ' + document.title);
console.log('Loading time ' + elapsed + ' msec');
} else {
phantom.log('FAIL to load the address');
console.log('FAIL to load the address');
}
phantom.exit();
}

View File

@ -4,7 +4,7 @@ var cbfunc = function (data) {
globaldata= data;
var list = data.query.results.movie;
list.forEach(function (item) {
phantom.log(item.title + ' [' + item.rating.MPAA.content + ']');
console.log(item.title + ' [' + item.rating.MPAA.content + ']');
});
phantom.exit();
};

View File

@ -6,7 +6,7 @@ if (phantom.storage.length === 0) {
} else {
var list = document.querySelectorAll('div.bf');
for (var i in list) {
phantom.log(list[i].innerText);
console.log(list[i].innerText);
}
phantom.exit();
}

View File

@ -1,6 +1,6 @@
if (phantom.storage.length === 0) {
if (phantom.arguments.length !== 2) {
phantom.log('Usage: rasterize.js URL filename');
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
var address = phantom.arguments[0];

View File

@ -1,6 +1,6 @@
if (phantom.storage.length === 0) {
if (phantom.arguments.length !== 1) {
phantom.log('Usage: run-jasmine.js URL');
console.log('Usage: run-jasmine.js URL');
phantom.exit();
} else {
phantom.storage = 'run-jasmine';
@ -10,14 +10,14 @@ if (phantom.storage.length === 0) {
window.setInterval(function () {
var list, el, desc, i, j;
if (document.body.querySelector('.finished_at')) {
phantom.log(document.body.querySelector('.description').innerText);
console.log(document.body.querySelector('.description').innerText);
list = document.body.querySelectorAll('div.jasmine_reporter > div.suite.failed');
for (i = 0; i < list.length; ++i) {
el = list[i];
desc = el.querySelectorAll('.description');
phantom.log('');
console.log('');
for (j = 0; j < desc.length; ++j) {
phantom.log(desc[j].innerText);
console.log(desc[j].innerText);
}
}
phantom.exit();

View File

@ -7,7 +7,7 @@ var cbfunc = function (data) {
'July', 'August', 'September',
'October', 'November', 'December'];
list.forEach(function (item) {
phantom.log([item.name.replace(/\s/ig, ' '), ':',
console.log([item.name.replace(/\s/ig, ' '), ':',
names[item.atItsBestUntil], 'to',
names[item.atItsBestFrom]].join(' '));
});

View File

@ -6,7 +6,7 @@ if (phantom.storage.length === 0) {
} else {
var list = document.querySelectorAll('span.status');
for (var i = 0; i < list.length; ++i) {
phantom.log((i + 1) + ': ' + list[i].innerHTML.replace(/<.*?>/g, ''));
console.log((i + 1) + ': ' + list[i].innerHTML.replace(/<.*?>/g, ''));
}
phantom.exit();
}

View File

@ -3,6 +3,6 @@ if (phantom.storage.length === 0) {
phantom.userAgent = 'SpecialAgent';
phantom.open('http://www.httpuseragent.org');
} else {
phantom.log(document.getElementById('myagent').innerText);
console.log(document.getElementById('myagent').innerText);
phantom.exit();
}

View File

@ -4,17 +4,17 @@ if (phantom.storage.length === 0) {
city = phantom.arguments.join(' ');
}
phantom.storage = city;
phantom.log('Loading ' + city);
console.log('Loading ' + city);
phantom.open(encodeURI('http://www.google.com/ig/api?weather=' + city));
} else {
if (phantom.loadStatus === 'fail') {
phantom.log('Unable to access network');
console.log('Unable to access network');
phantom.exit(1);
}
if (document.querySelectorAll('problem_cause').length > 0) {
phantom.log('No data available for ' + phantom.storage);
console.log('No data available for ' + phantom.storage);
phantom.exit(1);
}
@ -23,18 +23,18 @@ if (phantom.storage.length === 0) {
return e.querySelector(s).attributes.data.value;
};
phantom.log('');
phantom.log('City: ' + data('weather > forecast_information > city'));
phantom.log('Current condition: ' + data('weather > current_conditions > condition'));
phantom.log('Temperature: ' + data('weather > current_conditions > temp_f') + ' F');
phantom.log(data('weather > current_conditions > humidity'));
phantom.log(data('weather > current_conditions > wind_condition'));
phantom.log('');
console.log('');
console.log('City: ' + data('weather > forecast_information > city'));
console.log('Current condition: ' + data('weather > current_conditions > condition'));
console.log('Temperature: ' + data('weather > current_conditions > temp_f') + ' F');
console.log(data('weather > current_conditions > humidity'));
console.log(data('weather > current_conditions > wind_condition'));
console.log('');
var forecasts = document.querySelectorAll('weather > forecast_conditions');
for (var i = 0; i < forecasts.length; ++i) {
var f = forecasts[i];
phantom.log(data('day_of_week', f) + ': ' +
console.log(data('day_of_week', f) + ': ' +
data('low', f) + '-' + data('high', f) + ' F ' +
data('condition', f));
}

View File

@ -45,6 +45,7 @@ public slots:
bool shouldInterruptJavaScript();
protected:
void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
QString userAgentForUrl(const QUrl &url) const;
private:
@ -58,6 +59,13 @@ WebPage::WebPage(QObject *parent)
m_userAgent = QWebPage::userAgentForUrl(QUrl());
}
void WebPage::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID)
{
if (!sourceID.isEmpty())
std::cout << qPrintable(sourceID) << ":" << lineNumber << " ";
std::cout << qPrintable(message) << std::endl;
}
bool WebPage::shouldInterruptJavaScript()
{
QApplication::processEvents(QEventLoop::AllEvents, 42);
@ -104,7 +112,6 @@ public:
public slots:
void exit(int code = 0);
void log(const QString &msg);
void open(const QString &address);
bool render(const QString &fileName);
void sleep(int ms);
@ -204,11 +211,6 @@ QString Phantom::loadStatus() const
return m_loadStatus;
}
void Phantom::log(const QString &msg)
{
std::cout << qPrintable(msg) << std::endl;
}
void Phantom::open(const QString &address)
{
m_page.triggerAction(QWebPage::Stop);