Caplin Trader 4.1.0

Class: module:caplin/core/log/AbstractLogger


An abstract class to make it easy to build loggers.

It provides log level handling, and de-multiplexes all the method calls onto a single method that takes two parameters: the name of the method ('trace'/'debug'/'info', etc) and an array of the arguments passed to that method.

To use it, you can either extend this class and override the log method or pass another logger to delegate to into the constructor, or finally you can pass a log method directly into the constructor.

The caplin logging scheme allows the logData to have a template string as the first item. You can convert a logData into a string using the method this.logDataToString from inside your log method.

By default there is no data or log level information added into that string, so you will most probably want to prepend the time and level. Here is a simple example that logs to the console (although if you wish to do this, check out caplin.core.log.ConsoleLogger):

function MyLogger() {;
caplin.extend(MyLogger, caplin.core.log.AbstractLogger);
MyLogger.prototype.log = function(level, logData) {
	 console.log(new Date().toISOString(), level, this.logDataToString(logData));


new module:caplin/core/log/AbstractLogger(level, delegateopt)

Constructs an AbstractLogger. Will usually be called in the super constructor of subclasses.
Name Type Attributes Description
level Number the level at which to log messages. Should be one of the static levels defined on this class. Will default to the most fine level if not provided.
delegate function <optional>
function or other module:caplin/core/log/Logger to delegate logging to. Do not provide a delegate if you are sub-classing this class and overriding the log method.