Fleet Freedom
Main Site
Overview
WebSocket
JavaScript
Behaviours
Provisioning
Pictures
Reports
Events
Return to site

Debugging Behaviours

New Feature
New in 4.4
Tuesday, February 28, 2017
By Alex Lein

New in Fleet Freedom v4.4 are two new tools to help script writers trace and debug their scripts. In previous versions, these tools were not available outside of the Trak iT development team.

Behaviour Log Messages

The obvious way to debug your scripts is to write log messages in the same way you'd use a console window. To that end, there is a new object, debug, embedded in the execution context which contains four methods; log, info, warn, and err.

Each method takes either one string, or an arbitrary number of arguments or any type.

If one, string type argument is provided, the value is written to the behaviourLog.message.

Any other argument(s) are serialized as JSON and written to behaviourLog.message.

debug.log("this is a log message");
debug.info("information message about an array", [1, 2, 3]);
debug.warn({ warning: "msg" }, [ "and", "array" ], "third");
debug.err("does not throw an exception, but it is logged as one.");

In addition to your own log messages, uncaught exceptions and syntax errors are also sent as BehaviourLogType.err type messages.

behaviourLog Subscription Type

Using the WebSocket, the behaviourLog SubscriptionType allows you to receive your BehaviourLog messages almost instantly.  Each message contains a reference to the BehaviourScript, Behaviour, and Asset, so you can figure out where an issue originates.

An example (based on the debug.warn example above) would be: behaviourLog {
"company": 42,
"asset": 456789,
"script": 123,
"behaviour": 56789,
"id": 123456789,
"v": [1],
"dts": "2017-03-07T17:19:24.813Z",
"kind": "warn",
"line": 13,
"character": 7,
"message": "[{"warning":"msg"},["and","array"],"third"]"
}

The documentation for the BehaviourLog format can be found in the API reference.

Please note that any calls to debug.log (or other debug methods) will generate log messages during execution, but they are sent asynchronously across the WebSocket, and only after the script has finished execution.

  • Back to Behaviours Articles
  • Full Behaviours Reference
Trak iT® Wireless and Fleet Freedom® are Trademarks of Trak iT® Wireless Inc.
All content contained within this site is the property of Trak iT® Wireless unless otherwise stated.