TransportDelegate (Interface)

About

This interface defines the API for transport delegates. Transport delegates do the actual work of logging, taking a log info object and writing it somewhere.

When writing a transport delegate, keep these guidelines in mind:

  • You must implement the .log() function. This is required.

  • If your delegate uses resources that need to be cleaned up when the parent transport is closed, implement the .transportWillClose() function.

  • If your delegate manages a resource that logically can be reset or cleared, implement the .clear() function.

NOTE

In the constructor, a transport delegate is a non-shared object. If the delegate is attached to a shared global logger (which is usually the case), in the other class functions it will be a shared object, which means any modifications to the delegate’s properties must be wrapped in Use (This)/End use.

API

constructor()

cs.js.TransportDelegate.new(transport : cs.js.Transport; options : Object)

Creates a new TransportDelegate instance. options is the .delegateOptions property of the options passed to the Transport constructor.

You are not required to implement a constructor in your transport delegates.


.clear()

.clear()

This function, if defined, is called by Logger.clear() to “clear” the transport delegate’s output. It is up to the delegate to decide what “clearing” means. For example, if the delegate writes to a file, this function might truncate the file.


.log()

.log(info : Object)

This is the only required function in a transport delegate. It is called by the parent Transport to log a message. info is a log info object.

When this function is called, info.level has been set to a valid log level, and info.message has been formatted by the parent Transport and the parent Logger.


.transportWillClose()

.transportWillClose()

This function, if defined, is called when replacing or removing a transport from a logger, or when closing a logger. It should perform any necessary cleanup, for example closing open files.

NOTE

If you are using a transport delegate that manages resources, you should probably implement this function.

Last Updated:
Contributors: Aparajita