Comparing version 0.8.3 to 0.9.0
@@ -24,2 +24,3 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
var _ = require('lodash'); | ||
var AbstractNetworkMessage = require('./message/abstract_network_message'); | ||
@@ -74,14 +75,11 @@ var AbstractTransport = require('./transport/abstract_transport'); | ||
Client.prototype._traceLogWithMessage = function(str, message) { | ||
str = '<' + this._partialSessionToken + '> ' + str; | ||
// Only perform toJSON when trace which actually be emitted, perform on toString | ||
var messageDescriber = function() {}; | ||
messageDescriber.toString = function() { | ||
return JSON.stringify(message.toJSON()); | ||
}; | ||
logger.trace(str, { | ||
sessionToken: this.session.token, | ||
message: messageDescriber | ||
}); | ||
Client.prototype._debugLogWithMessage = function(str, message) { | ||
var meta = {}; | ||
if (this.session.params) { | ||
_.extend(meta, this.session.params); | ||
} | ||
meta.sessionToken = this.session.token; | ||
meta.messageType = message.constructor.name; | ||
meta.message = message; | ||
debug(str, meta); | ||
}; | ||
@@ -102,7 +100,7 @@ | ||
if (err) { | ||
debug('Failed to send message due to error', err); | ||
debug('Failed to send message due to error', {error: err}); | ||
return callbackOrEmitError(this, callback, err); | ||
} | ||
this._traceLogWithMessage('Sent message', message); | ||
this._debugLogWithMessage('Sent message to client', message); | ||
maybeCallback(callback)(); | ||
@@ -256,3 +254,3 @@ }.bind(this)); | ||
if (!(message instanceof PingMessage)) { | ||
this._traceLogWithMessage('Received message', message); | ||
this._debugLogWithMessage('Received message from client', message); | ||
} | ||
@@ -259,0 +257,0 @@ |
@@ -23,2 +23,3 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
var debug = require('debug'); | ||
var util = require('util'); | ||
var winston = require('winston'); | ||
@@ -95,2 +96,3 @@ | ||
componentName = 'jetstream:' + componentName; | ||
var debugLog = getDebugLogger(componentName); | ||
@@ -100,3 +102,5 @@ | ||
debugLog(message); | ||
_debug.call(_logger, '[' + componentName + '] ' + message); | ||
_debug.call(_logger, componentName + ' ' + message, { | ||
category: componentName | ||
}); | ||
} else { | ||
@@ -107,3 +111,6 @@ var args = Array.prototype.slice.call(arguments, 2); | ||
args[0] = '[' + componentName + '] ' + args[0]; | ||
args[0] = componentName + ' ' + args[0]; | ||
if (args.length === 2 && typeof args[1] === 'object' && typeof args[1] !== null) { | ||
args[1].category = componentName; | ||
} | ||
_debug.apply(_logger, args); | ||
@@ -133,2 +140,18 @@ } | ||
// Enhance default debug.formatArgs to get colors and deeper inspection | ||
var formatArgs = debug.formatArgs; | ||
debug.formatArgs = function debugFormatArgs() { | ||
var args = formatArgs.apply(this, arguments); | ||
var array = Array.prototype.slice.call(args, 0); | ||
var useColors = this.useColors; | ||
if (array.length > 1) { | ||
return [array[0]].concat(array.slice(1).map(function(arg) { | ||
return util.inspect(arg, {depth: 20, colors: useColors}); | ||
})); | ||
} else { | ||
return array; | ||
} | ||
}; | ||
var debugLogByComponent = {}; | ||
@@ -138,3 +161,3 @@ function getDebugLogger(componentName) { | ||
if (!debugLog) { | ||
debugLog = debug('jetstream:' + componentName); | ||
debugLog = debug(componentName); | ||
debugLogByComponent[componentName] = debugLog; | ||
@@ -141,0 +164,0 @@ } |
@@ -366,3 +366,10 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
if (!Array.isArray(newValue)) { | ||
debug('Bad non-array value for property \'' + property.name + '\''); | ||
var message = 'Setting non-array value for collection property \'' + | ||
property.name + '\''; | ||
debug(message, { | ||
uuid: this.uuid, | ||
typeName: this.typeName, | ||
propertyName: property.name, | ||
typeOfNewValue: typeof newValue | ||
}); | ||
return this[property.key]; | ||
@@ -375,3 +382,10 @@ } | ||
} catch(err) { | ||
debug(err.message); | ||
var message = 'Setting value for collection property \'' + | ||
property.name + '\' raised error'; | ||
debug(message, { | ||
error: err, | ||
uuid: this.uuid, | ||
typeName: this.typeName, | ||
propertyName: property.name | ||
}); | ||
return this[property.key]; | ||
@@ -400,3 +414,10 @@ } | ||
} catch(err) { | ||
debug(err.message); | ||
var message = 'Setting value for property \'' + | ||
property.name + '\' raised error'; | ||
debug(message, { | ||
error: err, | ||
uuid: this.uuid, | ||
typeName: this.typeName, | ||
propertyName: property.name | ||
}); | ||
return this[property.key]; | ||
@@ -579,3 +600,2 @@ } | ||
if (err) { | ||
debug('setting ModelObject as scope root failed', err); | ||
return callbackOrEmitError(this, callback, err); | ||
@@ -595,3 +615,7 @@ } | ||
if (err) { | ||
debug('setting ModelObject as root for scope failed', err); | ||
debug('Setting ModelObject as root for scope failed', { | ||
error: err, | ||
uuid: this.uuid, | ||
typeName: this.typeName | ||
}); | ||
return callbackOrEmitError(this, callback, err); | ||
@@ -598,0 +622,0 @@ } |
@@ -40,4 +40,14 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
// Only attach request debugger if debug is enabled as it is expensive | ||
require('request-debug')(request, function(type, data, r) { | ||
debug(type, data); | ||
require('request-debug')(request, function(type, data, requestInstance) { | ||
var meta = {}; | ||
var scope = requestInstance.scope; | ||
if (scope) { | ||
if (scope.params) { | ||
_.extend(meta, scope.params); | ||
} | ||
meta.scopeUUID = scope.uuid; | ||
meta.scopeName = scope.name; | ||
} | ||
meta.data = data; | ||
debug(type, meta); | ||
}); | ||
@@ -162,3 +172,3 @@ } | ||
} | ||
this._executeRequest(url, headers, body, callback); | ||
this._executeRequest(scope, url, headers, body, callback); | ||
}.bind(this)); | ||
@@ -237,3 +247,3 @@ }; | ||
RemoteHttpSyncProcedure.prototype._executeRequest = function(url, headers, body, callback) { | ||
RemoteHttpSyncProcedure.prototype._executeRequest = function(scope, url, headers, body, callback) { | ||
var options = { | ||
@@ -250,3 +260,3 @@ url: url, | ||
this.httpClient(options, function(err, response, body) { | ||
var request = this.httpClient(options, function(err, response, body) { | ||
if (err || !response) { | ||
@@ -263,2 +273,7 @@ return callback(err || new Error('No response was returned')); | ||
}); | ||
if (request) { | ||
// Attach for later debugging | ||
request.scope = scope; | ||
} | ||
}; |
@@ -75,3 +75,8 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
if (middleware instanceof AbstractPersistMiddleware) { | ||
debug('scope "' + this.name + '" using persist middleware "' + middleware.constructor.name + '"'); | ||
var message = this.name + ' using persist middleware "' + | ||
middleware.constructor.name + '"'; | ||
debug(message, { | ||
scopeName: this.name, | ||
middlewareName: middleware.constructor.name | ||
}); | ||
this.persist = middleware; | ||
@@ -85,3 +90,5 @@ } else { | ||
if (middleware === null) { | ||
debug('scope "' + this.name + '" using no storage'); | ||
debug(this.name + ' using no storage', { | ||
scopeName: this.name | ||
}); | ||
this.storage = null; | ||
@@ -92,3 +99,8 @@ return; | ||
if (middleware instanceof StorageMiddleware) { | ||
debug('scope "' + this.name + '" using storage middleware "' + middleware.constructor.name + '"'); | ||
var message = this.name + ' using storage middleware "' + | ||
middleware.constructor.name + '"'; | ||
debug(message, { | ||
scopeName: this.name, | ||
middlewareName: middleware.constructor.name | ||
}); | ||
this.storage = middleware; | ||
@@ -95,0 +107,0 @@ } else { |
@@ -35,2 +35,4 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
var debug = logger.debug.bind(logger, 'core:session'); | ||
var CONST = {}; | ||
@@ -210,3 +212,3 @@ CONST.DEFAULT_INACTIVITY_EXPIRY_TIMEOUT = 10 * 60 * 1000; | ||
this.emit('expire'); | ||
logger.trace('Session expired', {sessionToken: this.token}); | ||
debug('Session expired', {sessionToken: this.token}); | ||
}; | ||
@@ -213,0 +215,0 @@ |
@@ -85,3 +85,6 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
if (err) { | ||
debug('failed to parse incoming data', err, data); | ||
debug('Failed to parse incoming data', { | ||
error: err, | ||
data: data | ||
}); | ||
this._pendingData = _.without(this._pendingData, entry); | ||
@@ -88,0 +91,0 @@ } else { |
{ | ||
"name": "jetstream", | ||
"version": "0.8.3", | ||
"version": "0.9.0", | ||
"description": "Jetstream Sync server framework to sync local and remote models", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"test-coveralls": "istanbul cover tape --report lcovonly -- test/index.js | tap-spec && cat ./coverage/lcov.info | coveralls", | ||
"start": "node demos/app.js", | ||
"start": "DEBUG=jetstream* node demos/app.js", | ||
"check-licence": "uber-licence --dry", | ||
@@ -31,0 +31,0 @@ "add-licence": "uber-licence" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
502653
11222