overlock-nodejs v1.1.2
Overlock Node.js library

The overlock Node.js library should allow logging of messages from the device, as well as on behalf of other devices and with associations.
NOTE: Unfortunately there is a concept of nodes in Overlock, which somewhat complicates references to node in this document. Wherever we mean Node.js, we will state it explicitly. All other references to node, are Overlock nodes.
API Docs
Install
The overlock library needs to have install called. This will patch on to console.log et al. in order to automatically pick up existing log messages in your application. This can be disabled.
import ol from 'overlock'
ol.install('node-process-name', { metadata: { version: '2.1.0' } })Signature
ol.install(processName, opts)
processNameA string, which is the name of the processoptsAn object with keys:metadataAn Object, which has key/value informationdisableConsoleLogBoolean. Default false. If True, messages fromconsole.logwill not be picked up by overlock.jsonReplacerA custom function to pass toJSON.stringifywhen encoding stateagentHostnameA string. Defaults tolocalhostagentPortA number. Defaults to6837
Logging
Logging is the primary way to capture information about the execution of a program in overlock.
Example:
// Basic logging
ol.log('This is a log message')
// Log as device
ol.log('This is as a different device', { logAs: 'device123' })
// Log with related device
ol.log('This is associated with the other node too', { related: 'device234' })
// Log with a level
ol.log('This is an error', { severity: 100 })
// Also with a pre-set level
ol.error('This is an error')Signature:
ol.log(msg, opts)
msgA string, which contains a message to debugoptsAn object with keys:severity: The log level (goes straight to agent API)logAs: Log as if the message were from another noderelated: Log with an association
ol.error, ol.warn, ol.debug, ol.info should all just be proxies to log with the log level set.
Lifecycle
Lifecycle events can be logged to allow high level information and events to be captured.
// Lifecycle event
ol.lifecycleEvent('boot', 'Booted up')
// For another device
ol.lifecycleEvent('network-disconnect', 'Unexpected Disconnected!', { logAs: 'device234' })Signature:
ol.lifecycleEvent(type, msg, opts)
typeA string type for a supported or custom lifecycle eventmsgA string which describes the eventoptsAn object with keys:logAs: Log as if the message were from another noderelated: Log with an association
Metadata
Allows storing of values about a node which do not change very often.
ol.updateMetadata({ version: '10.000' })
// For another device
ol.updateMetadata({ version: '10.000' }, { logAs: '12345' })Signature:
ol.updateMetadata(values, opts)
valuesAn object which contains the keys to merge in to the metadata. Values will be converted to strings, and Falsy values will be removed from metadata.optsAn object with keys:logAs: Log as if the message were from another node
Setting state
// set a key
ol.updateState({ sensor: 120 })
// delete a key
ol.deleteState({ sensor: false })
// As another device
ol.updateState({ sensor: 120 }, { logAs: '12345' })