mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	add logging of context store
This commit is contained in:
		| @@ -163,6 +163,7 @@ function start() { | ||||
|                 if (settings.httpStatic) { | ||||
|                     log.info(log._("runtime.paths.httpStatic",{path:path.resolve(settings.httpStatic)})); | ||||
|                 } | ||||
|                 redNodes.logContextStores(); | ||||
|                 redNodes.loadFlows().then(redNodes.startFlows).catch(function(err) {}); | ||||
|                 started = true; | ||||
|             }).catch(function(err) { | ||||
|   | ||||
| @@ -163,7 +163,9 @@ | ||||
|         "error-module-not-defined": "'module' is not defined in '__storage__' of settings.contextStorage", | ||||
|         "error-invalid-module-name": "Invalid context store name: '__name__'", | ||||
|         "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__]" | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -31,6 +31,27 @@ var defaultStore; | ||||
| // Whether there context storage has been configured or left as default | ||||
| var hasConfiguredStore = false; | ||||
|  | ||||
| // Unknown Stores | ||||
| var unknownStores = {}; | ||||
|  | ||||
| function logUnknownStore(name) { | ||||
|     var count = unknownStores[name] || 0; | ||||
|     if (count == 0) { | ||||
|         log.warn(log._("context.unknown-store", {name: name})); | ||||
|         count++; | ||||
|         unknownStores[name] = count; | ||||
|     } | ||||
| } | ||||
|  | ||||
| function logStores() { | ||||
|     for(var name in stores) { | ||||
|         if (name !== '_') { // ignore default store | ||||
|             var plugin = stores[name]; | ||||
|             log.info(log._("context.log-store-init", | ||||
|                            {name:name, info:plugin.info() })); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| function init(_settings) { | ||||
|     settings = _settings; | ||||
| @@ -158,6 +179,7 @@ function getContextStorage(storage) { | ||||
|         return stores[storage]; | ||||
|     } else if (stores.hasOwnProperty("_")) { | ||||
|         // Not known, but we have a default to fall back to | ||||
|         logUnknownStore(storage); | ||||
|         return stores["_"]; | ||||
|     } else { | ||||
|         // Not known and no default configured | ||||
| @@ -402,5 +424,6 @@ module.exports = { | ||||
|     get: getContext, | ||||
|     delete: deleteContext, | ||||
|     clean: clean, | ||||
|     close: close | ||||
|     close: close, | ||||
|     logStores: logStores | ||||
| }; | ||||
|   | ||||
| @@ -267,6 +267,24 @@ 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){ | ||||
|     return new LocalFileSystem(config); | ||||
| }; | ||||
|   | ||||
| @@ -124,6 +124,12 @@ Memory.prototype._export = function() { | ||||
|     return this.data; | ||||
| } | ||||
|  | ||||
| Memory.prototype.info = function() { | ||||
|     var self = this; | ||||
|     var conf = self.config; | ||||
|     var info = "module=memory"; | ||||
|     return info; | ||||
| } | ||||
|  | ||||
| module.exports = function(config){ | ||||
|     return new Memory(config); | ||||
|   | ||||
| @@ -223,5 +223,6 @@ module.exports = { | ||||
|     // Contexts | ||||
|     loadContextsPlugin: context.load, | ||||
|     closeContextsPlugin: context.close, | ||||
|     listContextStores: context.listStores | ||||
|     listContextStores: context.listStores, | ||||
|     logContextStores: context.logStores | ||||
| }; | ||||
|   | ||||
| @@ -18,6 +18,7 @@ var should = require("should"); | ||||
| var sinon = require('sinon'); | ||||
| var path = require("path"); | ||||
| var Context = require("../../../../../red/runtime/nodes/context/index"); | ||||
| var Log = require("../../../../../red/runtime/log"); | ||||
|  | ||||
| describe('context', function() { | ||||
|     describe('local memory',function() { | ||||
| @@ -792,4 +793,37 @@ 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(); | ||||
|             }); | ||||
|         }); | ||||
|     }); | ||||
| }); | ||||
|   | ||||
| @@ -376,7 +376,7 @@ describe('localfilesystem',function() { | ||||
|         }); | ||||
|     }); | ||||
|  | ||||
|     describe('if cache is enabled',function() { | ||||
|     describe('#if cache is enabled',function() { | ||||
|         afterEach(function() { | ||||
|             return context.clean([]).then(function(){ | ||||
|                 return context.close().then(function(){ | ||||
| @@ -496,4 +496,12 @@ 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"); | ||||
|         }); | ||||
|     }); | ||||
| }); | ||||
|   | ||||
| @@ -214,4 +214,11 @@ describe('memory',function() { | ||||
|         }); | ||||
|     }); | ||||
|  | ||||
|     describe('#info',function() { | ||||
|         it('should return info', function() { | ||||
|             var info = context.info(); | ||||
|             info.should.be.equal("module=memory"); | ||||
|         }); | ||||
|     }); | ||||
|  | ||||
| }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user