On-device Logging

One area of concern, when shipping software out to remote devices, is how to get visibility of any client side logs and/or crash reports. At MobileCaddy we understand that having access to these logs can be the difference between an OK mobile experience for your users, and one that is a robust, ever improving, critical piece of their daily workflow.

With this in mind we expose a logger module as an Angular service that can be included in your code, and replace your standard use of console.log. The logger module will still output to your browser JavaScript console when running in Codeflow, so you still have access to useful development and debug information. It will also conditionally write logs into a special pre-mobilised table called Mobile_Log__mc. This table shall be included in full synchronisation calls by default. It can also be synchronised explicitly through the standard synchronisation calls.

The logger calls accept any number of arguments, of any type, so there’s no need to JSON.stringify them before passing them in.

The logger service supports debug, info, log, warn and error calls.

Logs are conditionally written to the Mobile_Log__mc table based upon the optional logLevel localStorage entry (default is 0). Logs are written if the logLevel value matches (or is greater than) the associated value for each log type.

  • 0 : ERROR
  • 1 : WARN
  • 2: LOG
  • 3: INFO
  • 4: DEBUG

When the log is written to the Mobile_Log__mc table it’s respective log level is added to the entry (prefixed with a “D”).

Example Call

Screenshot of the MobileCaddy logger in action, showing result in the Chrome developer console.

Associated DB Entry

Field: mobilecaddy1__Error_Text__c
Value: “{“0″:”MyError”,”1″:{“name”:”myObject”},”2″:123}”

Suggested Usage

Use of logger.error is strongly suggested for scenarios where your JavaScript code throws an exception on in scenarios deemed to be critical failures. These include when calls to the MobileCaddy devUtils return rejections to their promises.

For scenarios where your application runs into scenarios that are unexpected you can also use logger.error, especially for early releases of the applications.

How To

This extract from the AppRunService (available in the MobileCaddy shell and seeds apps) demonstrates dependency injection and basic usage;

Full logger call information can be found in the MobileCaddy API specification.