Skip to content

Commit

Permalink
Merge branch 'feature/#190-file-logger' of github.com:deepstreamIO/de…
Browse files Browse the repository at this point in the history
…epstream.io into feature/#190-file-logger
  • Loading branch information
yasserf committed Jun 21, 2016
2 parents b9f262e + f9419fb commit 15cf514
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 34 deletions.
1 change: 0 additions & 1 deletion conf/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# General
serverName: UUID # Each server within a cluster needs a unique name. Set to UUID to have deepstream autogenerate a unique id
colors: true # Use colors when logging. (This looks good in a console, but will leave color markers in logfiles)
showLogo: true # Show the deepstream logo on startup (highly recommended)
logLevel: INFO # Log messages with this level and above. Valid levels are DEBUG, INFO, WARN, ERROR, OFF

Expand Down
73 changes: 48 additions & 25 deletions src/config/config-initialiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const fileUtils = require( './file-utils' );
var commandLineArguments;

/**
* Takes a configuration object and instantiates functional properties
* Takes a configuration object and instantiates functional properties.
* CLI arguments will be considered.
*
* @param {Object} config configuration
*
Expand Down Expand Up @@ -45,7 +46,8 @@ function handleUUIDProperty( config ) {
}

/**
* Replace the ssl config with paths
* Load the SSL files
* CLI arguments will be considered.
*
* @param {Object} config deepstream configuration object
*
Expand All @@ -71,7 +73,8 @@ function handleSSLProperties( config ) {
}

/**
* Transform log level string (enum) to its internal value
* Initialize the logger and overwrite the root logLevel if it's set
* CLI arguments will be considered.
*
* @param {Object} config deepstream configuration object
*
Expand All @@ -96,30 +99,36 @@ function handleLogger( config ) {
}

/**
* Handle the plugins property in the config object
* for logger and the connectors.
* Modifies the config object and load the logger and connectors
* and passing options for the connectors
* Plugins can be passed either as a `path` property - a relative to the
* working directory, or the npm module name - or as a `name` property with
* a naming convetion: `{message: {name: 'redis'}}` will be resolved to the
* npm module `deepstream.io-msg-direct`
* cliOptions can modify the lookup path for the plugins via libPrefix property
*
* @todo refactor
* Handle the plugins property in the config object the connectors.
* Allowed types: {message|cache|storage}
* Plugins can be passed either as a __path__ property or as a __name__ property with
* a naming convetion: *{cache: {name: 'redis'}}* will be resolved to the
* npm module *deepstream.io-cache-direct*
* Exception: *message* will be resolved to *msg*
* Options to the constructor of the plugin can be passed as *options* object.
*
* CLI arguments will be considered.
*
* @param {Object} config deepstream configuration object
* @param {Object} argv CLI arguments from the CLI interface
*
* @private
* @returns {void}
*/
function handlePlugins( config, argv ) {
function handlePlugins( config ) {
if ( config.plugins == null ) {
return;
}
var connectors = {
'messageConnector': 'msg',
// mappnig between the root properties which contains the plugin instance
// and the plugin configuration objects
var connectorMap = {
'messageConnector': 'message',
'cache': 'cache',
'storage': 'storage'
};
// mapping between the plugin configuration properties and the npm module
// name resolution
var typeMap = {
'message': 'msg',
'cache': 'cache',
'storage': 'storage'
};
Expand All @@ -132,15 +141,27 @@ function handlePlugins( config, argv ) {
for ( let key in plugins ) {
var plugin = plugins[key];
if ( plugin != null ) {
var pluginConstructor = resolvePluginClass( plugin, connectors[key] );
var pluginConstructor = resolvePluginClass( plugin, typeMap[connectorMap[key]] );
config[key] = new pluginConstructor( plugin.options );
}
}
}

/**
* Instantiate the given plugin, which either needs a path property or a name
* property which fits to the npm module name convention. Options will be passed
* to the constructor.
*
* CLI arguments will be considered.
*
* @param {Object} config deepstream configuration object
*
* @private
* @returns {Function} Instance return be the plugin constructor
*/
function resolvePluginClass( plugin, type ) {
// nexe needs global.require for "dynamic" modules
// but browserify and proxyquire can't handle global.require
// nexe needs *global.require* for __dynamic__ modules
// but browserify and proxyquire can't handle *global.require*
var req = global && global.require ? global.require : require;
var requirePath;
var pluginConstructor;
Expand All @@ -160,8 +181,9 @@ function resolvePluginClass( plugin, type ) {
}

/**
* Instantiates the authenticationhandler registered for
* config.auth.type
* Instantiates the authentication handler registered for *config.auth.type*
*
* CLI arguments will be considered.
*
* @param {Object} config deepstream configuration object
*
Expand Down Expand Up @@ -196,8 +218,9 @@ function handleAuthStrategy( config ) {
}

/**
* Instantiates the permissionhandler registered for
* config.auth.type
* Instantiates the permission handler registered for *config.permission.type*
*
* CLI arguments will be considered.
*
* @param {Object} config deepstream configuration object
*
Expand Down
9 changes: 5 additions & 4 deletions src/config/file-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const path = require( 'path' );
*/
exports.lookupLibRequirePath = function( filePath ) {
return exports.lookupRequirePath( filePath, global.deepstreamLibDir );
}
};

/**
* Append the global configuration directory as the prefix to any path
Expand All @@ -25,11 +25,12 @@ exports.lookupLibRequirePath = function( filePath ) {
*/
exports.lookupConfRequirePath = function( filePath ) {
return exports.lookupRequirePath( filePath, global.deepstreamConfDir );
}
};

/**
* If a prefix is not set the filePath will be returned
* Resolve a path which will be passed to *require*.
*
* If a prefix is not set the filePath will be returned
* Otherwise it will either replace return a new path prepended with the prefix.
* If the prefix is not an absolute path it will also prepend the CWD.
*
Expand Down Expand Up @@ -82,7 +83,7 @@ exports.fileExistsSync = function( filePath ) {
} catch( e ) {
return false;
}
}
};

/**
* Append the prefix to the current working directory,
Expand Down
4 changes: 2 additions & 2 deletions src/config/js-yaml-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports.loadConfig = function( args ) {
var configPath = setGlobalConfigDirectory( argv );
var configString = fs.readFileSync( configPath, { encoding: 'utf8' } );
var rawConfig = parseFile( configPath, configString );
var config = extendConfig( rawConfig, argv, path.dirname( configPath ) );
var config = extendConfig( rawConfig, argv );

return {
config: configInitialiser.initialise( config ),
Expand Down Expand Up @@ -127,7 +127,7 @@ function setGlobalLibDirectory( argv ) {
* @private
* @returns {Object} extended config
*/
function extendConfig( config, argv, configDir ) {
function extendConfig( config, argv ) {
var cliArgs = {};
var key;

Expand Down
16 changes: 14 additions & 2 deletions src/deepstream.io.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ Deepstream.prototype.set = function( key, value ) {
/**
* Starts up deepstream. The startup process has three steps:
*
* - Initialise all dependencies (cache connector, message connector, storage connector and logger)
* - First of all initialise the logger and wait for it (ready event)
* - Then initialise all other dependencies (cache connector, message connector, storage connector)
* - Instantiate the messaging pipeline and record-, rpc- and event-handler
* - Start TCP and HTTP server
*
Expand All @@ -118,6 +119,14 @@ Deepstream.prototype.start = function() {
}
};

/**
* This is the actual function which starts deepstream. It is invoked after+
* the logger was intialized or emitted the read event if it was initialized
* asynchronously
*
* @private
* @returns {void}
*/
Deepstream.prototype._start = function() {
this._showStartLogo();

Expand Down Expand Up @@ -190,9 +199,12 @@ Deepstream.prototype.convertTyped = function( value ) {

/**
* Synchronously loads a configuration file
* Initialization of plugins and logger will be triggered by the
* configInitialiser, but it should not block. Instead the ready events of
* those plugins are handled through the DependencyInitialiser in this instnace.
*
* @param {Object} config Configuration object
*
* @private
* @returns {void}
*/
Deepstream.prototype._loadConfig = function( config ) {
Expand Down

0 comments on commit 15cf514

Please sign in to comment.