About logging

Caplin’s Core Library enables you to generate custom log messages of various severity levels, from anywhere within your application.

Application logging is available via the caplin.core.log.Log singleton. Messages can be logged at various levels, and filtered by their source. The text of a message can be created using either a fixed string or token replacements. Typically, a class constructor will create a logger with the source set to the class name. This logger will then be used for all logging within the class. For example, in class constructor:

this.log = caplin.core.log.Log.getLogger("my.class.Name");

With the above logger created as a class member variable (the source/class name set to "my.class.Name"), messages can be logged throughout the class using a text string, like this:

this.log.warn("a message");

…or using token replacements, like this:

this.log.info("Latency: {0}, Queue Size: {1}",  sLatency, sQueueSize);

The messages logged will be sent to all registered caplin.core.log.Loggers. Caplin provides two Logger implementations:

Users can create their own Loggers by implementing the caplin.core.log.Logger interface. Loggers are registered with the logging system using the caplin.core.log.Log.register method:

var oLogger = new caplin.core.log.ConsoleLogger(); // create the logger
caplin.core.log.Log.register(oLogger, "*"); // register logger

The second argument to register() is a pattern that allows you to filter log messages based on the source of the message. For example: a pattern of "caplin.trading." will only receive messages logged within the trading library, "" will log messages from all sources.

For more information see the API docs for the caplin.core.log.Log namespace.