Log system interface library for Signal K node plugins.
Provides two small classes.
The Log class supports message logging to the Signal K dashboard and host system logs.
The DebugLog class supports logging to the host system logs dependent upon the presence of debug keys in the environment DEBUG variable.
const Log = require("signalk-liblog/Log.js");
/**********************************************************************
* Create new log instance, setting the message prefix to be used for
* system log messages and 'normal' and 'error' callback functions that
* will be used to interface to the Signal K dashboard.
*/
const log = new Log(plugin.id, { ncallback: app.setProviderStatus, ecallback: app.setProviderError });
/**********************************************************************
* Issue a 'normal', 'warning' and 'error' messages to both the system
* log and through the Signal K dashboard callbacks.
*/
log.N("server listening on UDP port %d", udpPort);
log.W("using default UDP port %d", udpPort);
log.E("error opening UDP port %d", udpPort);
/**********************************************************************
* Issue an 'error' message to just the system log.
*/
log.E("server rejected invalid client", false);
Log(prefix [, options ])
Create a new Log instance. prefix is arbitrary text that will be prepended to messages written to the system log. options is object perhaps containing the following properties.
options.ncallback - callback function to be used for normal messages (i.e.
those generated by a call to the N
method.
Defaults to undefined.
options.wcallback - callback function to be used for warning messages (i.e.
those generated by a call to the W
method.
Defaults to options.ncallback.
options.ecallback - callback function to be used for error messages (i.e.
those generated by a call to the E
method.
Defaults to *options.ncallback.
options.prefixall - boolean value which if true causes prefix to be prepended to all output (and not just system log output). Defaults to false.
N(message [, nocallback ])
Write a 'normal' message of the form "prefix: message" to the system log and, by default, pass a message of the form "message" to the normal callback function defined when this Log object was instantiated.
message is any arbitrary text.
nocallback is a boolean which if set to true prevents the callback.
W(message [, nocallback ])
Write a 'warning' message of the form "prefix
message is any arbitrary text.
nocallback is a boolean which if set to true prevents the callback.
E(message [, nocallback ])
Write an 'error' message of the form "prefix:error: message" to the system log and, by default, pass a message of the form "message" to the error callback function defined when this Log object was instantiated.
message is any arbitrary text.
nocallback is a boolean which if set to true prevents the callback.