Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
There's a reason why many "Hello World" tutorials begin with writing to the logging tool. Developers live in the console, inserting breakpoints and watching variables while debugging. Especially with interconnected, complex systems, logging becomes crucial to saving developer hours and shipping on time.
What this tutorial covers
This tutorial introduces the three principal methods of monitoring the status of assets and the output of operations on an Axeda instance.
The Audit Log
You can filter the Audit Log by date range or by category.
A list of the Audit Categories is available in the Help documentation at http://<<yourhost>>.axeda.com/help/en/audit_log_categories_for_filtering...
You can write to the Audit Log from an Expression Rule or from a Custom Object.
Writing to the Audit Log from an Expression Rule
Use the Audit Action to write to the Audit Log:
Audit("data-management", "The temperature " + DataItem.temp.value + "was reported at " + FormatDate(Now(), "yyyy/MM/dd hh:mm:ss"))
You can insert values from the Variables or Functions list by using the plus operator as a string concatenator.
Writing to the Audit Log from a Custom Object
import com.axeda.common.sdk.id.Identifier
import com.axeda.drm.sdk.Context
import com.axeda.drm.sdk.audit.AuditCategory
import com.axeda.drm.sdk.audit.AuditMessage
auditMessage(Context.getSDKContext(), "data_management", "Thread started timestamp has ended.", context.device.id)
private def auditMessage(Context CONTEXT, String category, String message, Identifier assetId) {
AuditCategory auditCategory = AuditCategory.getByString(category) ?: AuditCategory.DATA_MANAGEMENT
if (assetId == null) {
new AuditMessage(CONTEXT, "com.axeda.drm.rules.functions.AuditLogAction", auditCategory, [message]).store()
} else {
new AuditMessage(CONTEXT, "com.axeda.drm.rules.functions.AuditLogAction", auditCategory, [message], assetId).store()
}
}
In either case, a message written in the context of an Asset will be displayed on the Asset Dashboard (assuming the Audit module is enabled for the Asset Dashboard in the Model Preferences).
The Custom Object Log
The Configuration (6.1-6.5)/Manage(6.6+) tab provides access to the Custom Objects log when they are selected from the View sub-menu:
This links allows you to open or save a zip archive of text files called customobject.logX where X is a digit that indicates that the log has rolled over into the next file (ie, customobject.log1). The most current is customobject.log without a digit. These files contain logging information in chronological order, identified by Custom Object name. The log contains full stack traces of exceptions, as well as text written to the log.
ERROR 2013-06-20 18:26:02,613 [sstreBinaryReturn,ajp-10.16.70.164-8009-6] Exception occurred in sstreBinaryReturn.groovy: java.lang.NullPointerException
at com.axeda.platform.sdk.v1.services.extobject.ExtendedObject.getPropertyByName(ExtendedObject.java:276)
at com.axeda.platform.sdk.v1.services.extobject.ExtendedObject$getPropertyByName.call(Unknown Source)
The Logger object in Custom Objects is a custom class ScriptoDebuggerLogger that is injected into the script and does not need to be explicitly imported.
The following attributes are available for the Logger object:
logger.info()
logger.debug()
logger.error()
All objects can be converted to a String by using the dump() function.
logger.info(context.device.dump())
Additionally, a Javascript utility can be used with all SDK v2 domain objects and some SDK v1 domain objects to get a JSON pretty-print string of their attributes.
import net.sf.json.JSONArray
logger.info(JSONArray.fromObject(context.device).toString(2))
// Outputs:
[{
"buildVersion": "",
"condition": {
"detail": "",
"id": "3",
"label": "",
"restUrl": "",
"systemId": "3"
},
"customer": {
"detail": "",
"id": "2",
"label": "Default Organization",
"restUrl": "",
"systemId": "2"
},
"dateRegistered": {
"date": 31,
"day": 4,
"hours": 18,
"minutes": 39,
"month": 0,
"seconds": 31,
"time": 1359657571070,
"timezoneOffset": 0,
"year": 113
},
"description": "",
"detail": "mwc_location_1",
"details": null,
"gateways": [],
"id": "12345",
"label": "",
"location": {
"detail": "Default Organization",
"id": "2",
"label": "Default Location",
"restUrl": "",
"systemId": "2"
},
"model": {
"detail": "mwc_location",
"id": "4321",
"label": "standalone",
"restUrl": "",
"systemId": "4321"
},
"name": "mwc_location_1",
"pingRate": 10000,
"properties": [],
"restUrl": "",
"serialNumber": "mwc_location_1",
"sharedKey": [],
"systemId": "12345",
"timeZone": "America/New_York"
}]
Custom object logs may be retrieved by navigating to the Configuration (6.1-6.5)/Manage(6.6+) tab and selecting Custom Objects from the View sub-menu. Click the "Log" button at the bottom of the table and save, then view customobject.log in a text editor.
Reports
Reports provide a summary of data about the state of objects on the Axeda Platform. Report titles are generally indicative of what they're reporting, such as Missing Devices Report, Auditing Report, Users Report.
A separate license is needed in order to use the Reports feature. New report types can only be created by a Reports administrator.
To run a report, click Run from the Reports Tab.
You can manage Reports from the Administration tab.
These three tools together offer a full view of the state of domain objects on the Axeda Platform. Make sure to take advantage of them while troubleshooting assets and applications.
Nice tool and want to suggest JSON Pretty Print tool.