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

use implicit logging of context store

This commit is contained in:
Hiroyasu Nishiyama 2018-07-20 23:26:47 +09:00
parent 65e67b6c3e
commit a29527ec96
8 changed files with 11 additions and 87 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,9 +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.logContextStores(); redNodes.loadContextsPlugin().then(function () {
redNodes.loadFlows().then(redNodes.startFlows).catch(function(err) {}); redNodes.loadFlows().then(redNodes.startFlows).catch(function(err) {});
started = true; started = true;
});
}).catch(function(err) { }).catch(function(err) {
console.log(err); console.log(err);
}); });

View File

@ -45,13 +45,10 @@ function logUnknownStore(name) {
} }
} }
function logStores() { function logStore(name, module) {
for(var name in stores) {
if (name !== '_') { // ignore default store if (name !== '_') { // ignore default store
var plugin = stores[name];
log.info(log._("context.log-store-init", log.info(log._("context.log-store-init",
{name:name, info:plugin.info() })); {name:name, info:"module="+module}));
}
} }
} }
@ -116,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()})));
} }
@ -426,6 +424,5 @@ module.exports = {
get: getContext, get: getContext,
delete: deleteContext, delete: deleteContext,
clean: clean, clean: clean,
close: close, close: close
logStores: logStores
}; };

View File

@ -267,24 +267,6 @@ LocalFileSystem.prototype.clean = function(activeNodes){
}); });
} }
LocalFileSystem.prototype.info = function() {
var self = this;
var conf = self.config;
var info = "module=localfilesystem";
if (conf) {
if (conf.hasOwnProperty("base")) {
info += ",base='"+conf.base+"'";
}
if (conf.hasOwnProperty("dir")) {
info += ",dir='"+conf.dir+"'";
}
if (conf.hasOwnProperty("cache")) {
info += ",cache";
}
}
return info;
}
module.exports = function(config){ module.exports = function(config){
return new LocalFileSystem(config); return new LocalFileSystem(config);
}; };

View File

@ -124,13 +124,6 @@ Memory.prototype._export = function() {
return this.data; return this.data;
} }
Memory.prototype.info = function() {
var self = this;
var conf = self.config;
var info = "module=memory";
return info;
}
module.exports = function(config){ module.exports = function(config){
return new Memory(config); return new Memory(config);
}; };

View File

@ -223,6 +223,5 @@ module.exports = {
// Contexts // Contexts
loadContextsPlugin: context.load, loadContextsPlugin: context.load,
closeContextsPlugin: context.close, closeContextsPlugin: context.close,
listContextStores: context.listStores, listContextStores: context.listStores
logContextStores: context.logStores
}; };

View File

@ -18,7 +18,6 @@ var should = require("should");
var sinon = require('sinon'); var sinon = require('sinon');
var path = require("path"); var path = require("path");
var Context = require("../../../../../red/runtime/nodes/context/index"); var Context = require("../../../../../red/runtime/nodes/context/index");
var Log = require("../../../../../red/runtime/log");
describe('context', function() { describe('context', function() {
describe('local memory',function() { describe('local memory',function() {
@ -794,36 +793,4 @@ describe('context', function() {
}); });
}); });
describe('log', function() {
it('should log context store info', function(done) {
Context.init({
contextStorage: {
memory: {
module: "memory",
congig: {
}
}
}
});
Context.load().then(function() {
var loginfo = undefined;
var logmsg = undefined;
sinon.stub(Log, 'log', function(msg) {
loginfo = msg;
});
sinon.stub(Log, '_', function(msg, info) {
logmsg = JSON.stringify(info);
return logmsg;
});
Context.logStores();
should.deepEqual(loginfo, {
level: Log.INFO,
msg: logmsg
});
Log.log.restore();
Log._.restore();
done();
});
});
});
}); });

View File

@ -497,11 +497,4 @@ describe('localfilesystem',function() {
}); });
}); });
describe('#info', function() {
it('should return info', function() {
var context = LocalFileSystem({dir: "/tmp", base: "xyz", cache: true});
var info = context.info();
info.should.be.equal("module=localfilesystem,base='xyz',dir='/tmp',cache");
});
});
}); });

View File

@ -214,11 +214,4 @@ describe('memory',function() {
}); });
}); });
describe('#info',function() {
it('should return info', function() {
var info = context.info();
info.should.be.equal("module=memory");
});
});
}); });