Caplin Trader 5.1.0

Class: module:ct-core/log/AbstractLogger

module:ct-core/log/AbstractLogger(level, delegateopt)

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 ConsoleLogger):

class MyLogger extends AbstractLogger {
 log(level, logData) {
   console.log(new Date().toISOString(), level, this.logDataToString(logData));
 }
}

Constructor

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

Constructs an AbstractLogger. Will usually be called in the super constructor of subclasses.

Extends:
Parameters:
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:ct-core/log/Logger to delegate logging to. Do not provide a delegate if you are sub-classing this class and overriding the log method.

Extends

Members

(inner) DEBUG

Logs at a level suitable for developers. May contain things like network level messages.

(inner) ERROR

Should only be used to log unrecoverable errors. The application will probably not continue to function correctly after one of these errors. Messages at this level should be readable by non-developers.

(inner) INFO

Logs messages that could be useful information. Messages at this level should be somewhat readable by non-developers.

(inner) TRACE

Logs at a very fine level, suitable for method entry / exits, etc.

(inner) WARN

Logs messages that may indicate problems, but where the system is able to continue. Messages at this level should be readable by non-developers.

Methods

debug()

Log a 'debug' message. A variable argument method. See module:ct-core/log/Log.interpolate for more information.

Inherited From:

error()

Log an 'error' message. A variable argument method. See module:ct-core/log/Log.interpolate for more information.

Avoid using this method, as it is intended only to be used at the top level.

Inherited From:

info()

Log an 'info' message. A variable argument method. See module:ct-core/log/Log.interpolate for more information.

Inherited From:

trace()

Log a 'trace' message. A variable argument method. See module:ct-core/log/Log.interpolate for more information.

Inherited From:

warn()

Log a 'warn' message. A variable argument method. See module:ct-core/log/Log.interpolate for more information.

Inherited From:

(inner) log(levelName, logData)

The abstract method that should be overridden by subclasses or by providing a delegate to the constructor.

Parameters:
Name Type Description
levelName String

the name of the method that was called.

logData Array

the log information.

(inner) logDataToString(logData) → {String}

Turns an array of logging data into a string according to the caplin logging scheme.

Parameters:
Name Type Description
logData Array

an array containing all the data that should be logged.

See:
  • module:ct-core/log/Log.interpolate for more information.
Returns:

A string representation of the logData provided.

Type
String

(inner) setLevel(level)

Changes the level at which this logger logs.

Parameters:
Name Type Description
level Number

a log level, chosen from those available on this class.