Moved the curl formatting into the log and changed the arguments for the log event listeneres to

receive both the "message" and the "curlCommand".

Added a "tracer" logger which allows you to create log files that a executable scripts. Those scripts
will write all of the log messages as script comments, and not comment out the curlCommands, so that they
can trace their application and use the generated script to recreate the issue.

Most changes are simply cased by adding the "unused" rule to jshint.
This commit is contained in:
Spencer Alger
2013-11-15 19:10:45 -07:00
parent 20804bb5ab
commit 5bb70fbe58
32 changed files with 185 additions and 229 deletions

View File

@ -16,6 +16,7 @@ var LoggerAbstract = require('../logger');
var _ = require('../utils');
function Console(config, bridge) {
// call my super
LoggerAbstract.call(this, config, bridge);
// config/state
@ -31,9 +32,11 @@ _.inherits(Console, LoggerAbstract);
Console.prototype.setupListeners = function (levels) {
// since some of our functions are bound a bit differently (to the console)
// create some of the bound properties manually
this.bound.onError = this.onError;
this.bound.onWarning = this.onWarning;
this.bound.onInfo = this.onInfo;
this.bound.onDebug = this.onDebug;
this.bound.onTrace = this.onTrace;
// call the super method
LoggerAbstract.prototype.setupListeners.call(this, levels);
@ -47,13 +50,13 @@ Console.prototype.setupListeners = function (levels) {
* @param {Error} e - The Error object to log
* @return {undefined}
*/
Console.prototype.onError = _.handler(function (e) {
Console.prototype.onError = function (e) {
if (console.error && console.trace) {
console.error(e.name === 'Error' ? 'ERROR' : e.name, e.stack || e.message);
} else {
console.log(e.name === 'Error' ? 'ERROR' : e.name, e.stack || e.message);
}
});
};
/**
* Handler for the bridges "warning" event
@ -97,11 +100,6 @@ Console.prototype.onDebug = function (msg) {
* @private
* @return {undefined}
*/
Console.prototype.onTrace = _.handler(function (method, url, body, responseBody, responseStatus) {
var message = 'curl "' + url.replace(/"/g, '\\"') + '" -X' + method.toUpperCase();
if (body) {
message += ' -d "' + body.replace(/"/g, '\\"') + '"';
}
message += '\n<- ' + responseStatus + '\n' + responseBody;
console.log('TRACE:\n' + message + '\n');
});
Console.prototype.onTrace = function (message, curlCall) {
console.log('TRACE:\n' + curlCall + '\n' + message);
};