1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #1818 from node-red-hitachi/context-store-logging

Add logging of context store
This commit is contained in:
Nick O'Leary 2018-07-20 20:23:32 +01:00 committed by GitHub
commit ab0fc2ecfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 6 deletions

View File

@ -90,7 +90,6 @@ function start() {
}) })
.then(function() { return storage.init(runtime)}) .then(function() { return storage.init(runtime)})
.then(function() { return settings.load(storage)}) .then(function() { return settings.load(storage)})
.then(function() { return redNodes.loadContextsPlugin()})
.then(function() { .then(function() {
if (log.metric()) { if (log.metric()) {
@ -163,8 +162,10 @@ function start() {
if (settings.httpStatic) { if (settings.httpStatic) {
log.info(log._("runtime.paths.httpStatic",{path:path.resolve(settings.httpStatic)})); log.info(log._("runtime.paths.httpStatic",{path:path.resolve(settings.httpStatic)}));
} }
redNodes.loadFlows().then(redNodes.startFlows).catch(function(err) {}); redNodes.loadContextsPlugin().then(function () {
started = true; redNodes.loadFlows().then(redNodes.startFlows).catch(function(err) {});
started = true;
});
}).catch(function(err) { }).catch(function(err) {
console.log(err); console.log(err);
}); });

View File

@ -163,7 +163,9 @@
"error-module-not-defined": "'module' is not defined in '__storage__' of settings.contextStorage", "error-module-not-defined": "'module' is not defined in '__storage__' of settings.contextStorage",
"error-invalid-module-name": "Invalid context store name: '__name__'", "error-invalid-module-name": "Invalid context store name: '__name__'",
"error-invalid-default-module": "Invalid storage '__storage__' is specified as a default storage", "error-invalid-default-module": "Invalid storage '__storage__' is specified as a default storage",
"error-use-undefined-storage": "Undefined storage '__storage__' is specified" "error-use-undefined-storage": "Undefined storage '__storage__' is specified",
"unknown-store": "Unknown store '__name__' specified. Use default store instead.",
"log-store-init": "Context store : '__name__' [__info__]"
} }
} }

View File

@ -31,6 +31,26 @@ var defaultStore;
// Whether there context storage has been configured or left as default // Whether there context storage has been configured or left as default
var hasConfiguredStore = false; var hasConfiguredStore = false;
// Unknown Stores
var unknownStores = {};
function logUnknownStore(name) {
if (name) {
var count = unknownStores[name] || 0;
if (count == 0) {
log.warn(log._("context.unknown-store", {name: name}));
count++;
unknownStores[name] = count;
}
}
}
function logStore(name, module) {
if (name !== '_') { // ignore default store
log.info(log._("context.log-store-init",
{name:name, info:"module="+module}));
}
}
function init(_settings) { function init(_settings) {
settings = _settings; settings = _settings;
@ -93,6 +113,7 @@ function load() {
try { try {
// Create a new instance of the plugin by calling its module function // Create a new instance of the plugin by calling its module function
stores[pluginName] = plugin(config); stores[pluginName] = plugin(config);
logStore(pluginName, plugins[pluginName].module);
} catch(err) { } catch(err) {
return reject(new Error(log._("context.error-loading-module",{module:pluginName,message:err.toString()}))); return reject(new Error(log._("context.error-loading-module",{module:pluginName,message:err.toString()})));
} }
@ -158,6 +179,7 @@ function getContextStorage(storage) {
return stores[storage]; return stores[storage];
} else if (stores.hasOwnProperty("_")) { } else if (stores.hasOwnProperty("_")) {
// Not known, but we have a default to fall back to // Not known, but we have a default to fall back to
logUnknownStore(storage);
return stores["_"]; return stores["_"];
} else { } else {
// Not known and no default configured // Not known and no default configured

View File

@ -124,7 +124,6 @@ Memory.prototype._export = function() {
return this.data; return this.data;
} }
module.exports = function(config){ module.exports = function(config){
return new Memory(config); return new Memory(config);
}; };

View File

@ -901,4 +901,5 @@ describe('context', function() {
}); });
}); });
}); });
}); });

View File

@ -478,7 +478,7 @@ describe('localfilesystem',function() {
}); });
}); });
describe('if cache is enabled',function() { describe('#if cache is enabled',function() {
afterEach(function() { afterEach(function() {
return context.clean([]).then(function(){ return context.clean([]).then(function(){
return context.close().then(function(){ return context.close().then(function(){