Module: LoggerManager

LoggerManager

This singleton should be used to obtain Logger instances to be used to produce the log.

Example

define(["LoggerManager"],function(LoggerManager) {
 
 //stuff
 var logger = LoggerManager.getLoggerProxy("myCategory");
 
 var MyClass = function() {
   //more stuff
   logger.info("my info log");
   //stuff
   logger.error("my error log");
 };
 
 return MyClass;
 
});

//elsewhere
require(["MyClass","LoggerManager","MyLoggerProvider"],
 function(MyClass,LoggerManager,MyLoggerProvider) {
 
 LoggerManager.setLoggerProvider(new MyLoggerProvider());
 var m = new MyClass(); //m will send log to the MyLoggerProvider instance
 
});

Method Summary

getLoggerProxy
Gets a LoggerProxy to be used to produce the log bound to a defined category.
setLoggerProvider
Sets the provider that will be used to get the Logger instances; it can be set and changed at any time.

Method Detail

<static> getLoggerProxy(cat) → {LoggerProxy}

Gets a LoggerProxy to be used to produce the log bound to a defined category. One single LoggerProxy instance will be created per each category: if the method is called twice for the same category then the same instance will be returned. On the other hand this method can potentially cause a memory leak as once a Logger is created it will never be dismissed. It is expected that the number of categories within a single application is somewhat limited and in any case not growing with time.
Parameters:
Name Type Description
cat String The category the Logger will be bound to.
Returns:
the instance to be used to produce the log for a certain category.
Type
LoggerProxy

<static> setLoggerProvider(newLoggerProvider)

Sets the provider that will be used to get the Logger instances; it can be set and changed at any time. All the new log will be sent to the Logger instances obtained from the latest LoggerProvider set. Log produced before any provider is set is discarded.
Parameters:
Name Type Argument Description
newLoggerProvider LoggerProvider <optional>
the provider to be used; if missing or null all the log will be discarded until a new provider is provided.