Example Code

Error Logger

Code and Documents

Attachment

   Data Acquisition Category Winner


error logger.png

Summary

The ability to Log Errors is an important part of any application, but it can be time consuming to implement for every application.

This example attempts to simplify this process by providing a reusable, generic Error Logger API that may be well suited to various of applications.

Video Demonstration

Here is a short video (no audio) demonstration of the Error Logger example.

<object id="scPlayer" width="1189" height="861" type="application/x-shockwave-flash" data="http://content.screencast.com/users/jgcode/folders/LabVIEW/media/61776c29-d71d-4d07-a412-0bde3f4553d..." >  <param name="movie" value="http://content.screencast.com/users/jgcode/folders/LabVIEW/media/61776c29-d71d-4d07-a412-0bde3f4553d..." />  <param name="quality" value="high" />  <param name="bgcolor" value="#FFFFFF" />  <param name="flashVars" value="thumb=http://content.screencast.com/users/jgcode/folders/LabVIEW/media/61776c29-d71d-4d07-a412-0bde3f4553d..." />  <param name="allowFullScreen" value="true" />  <param name="scale" value="showall" />  <param name="allowScriptAccess" value="always" />  <param name="base" value="http://content.screencast.com/users/jgcode/folders/LabVIEW/media/61776c29-d71d-4d07-a412-0bde3f4553d..." />  Unable to display content. Adobe Flash is required. </object>






Function

The Error Logger allows a developer to easily do the following in their applications without the need to write specific code to:

  • Check and trap errors - e.g. by simply placing a Check Error method at the end of a sequence of code
  • Log Errors to disk - without the need to manage log files or folders, it is all automatically handled by the API
  • View Error Logs using a generic User Interface - no need to build a custom UI
  • Programmatically show/hide the User Interface - control the UI using the API
  • Export Error Log files from the User Interface - allows a User to export a log file straight from the UI without digging through Error Log Folder manually
  • Manage and housekeep the Error Log folder - deletes old files when file limit reached, no need to worry about managing the Error Log Folder
  • Persists user options to disk - i.e. previous Export file name, these settings can be added to your Application Config File without doing an extra work, if no config exists, one is created
  • Broadcast messages when an error occurs - register for Events from the API so that you can respond with the appropriate actions in your application

Note: The Error Logger is not meant to replace providing Custom Error Handling - as that is specific to each application.

Steps to execute code

  1. Download error_logger-0.0.5-1_LV2009.zip
  2. Install both packages into VIPM (jgcode_lib_error_logger-0.0.5-1.ogp, jgcode_rsc_jgcode_library_palette-1.2-1.ogp)
    1. This package has no other dependencies.
  3. Open <zip>\Example\Error Logger Application Example.vi
  4. Follow the instructions on the Front Panel and Block Diagram of this VI.

OR

  1. Download Error Logger [Code Only].zip
  2. Open error logger.lvproj
  3. Open Error Logger Application Example
  4. Follow the instructions on the Front Panel and Block Diagram of this VI.

files.png

Distribution Notes

The Error Logger API is installed at <user.lib>\_JGCODE\error_logger

It is available through the palettes at: JGCODE Library\Error Logger (that is why jgcode_rsc_jgcode_library_palette-1.2-1.ogp needs to be installed)

The format of the Error Report in the Error files is adapted from VIPM - when I was looking for an example to use, I liked this format the best, and replicated it for this example.

Tested with LabVIEW 2009 and LabVIEW 2010.

Screenshots

screenshot.png

screenshot2.png

screenshot3.png

screenshot4.png

Note: Please ignore the Red Crosses in the palette, they do not impact this distribution in any way, only the way the icons in the palette look - I have already lodged the following CAR with NI - #185059.

VI Snippet

Please note I am unable to include a VI Snippet as it removes Front Panel decorations that contain instructions and changes the "This VI Refnum" to a constant, breaking the example.

Please see the example VI as per Steps To Execute Code above.


jgcode.png

Author's Notes

The Error Logger uses a Singleton architecture where a Class (data) is wrapped in a Data Value Reference (DVR).

This Reference is initialised on first call.

The DVR is stored in a Functional Global Variable (FGV) so it can be access anywhere throughout the application, but there is only ever one instance.

The DVR combined with the IPE makes creating wrappers for the Methods very easy.

VI attached below

Certified LabVIEW Architect * LabVIEW Champion

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
FraggerFox
Active Participant Active Participant
Active Participant
on

Is it necessary to have VIPM for this? Is it possible to use this without the use of OpenG?

Thanks

-FraggerFox!
Certified LabVIEW Architect, Certified TestStand Developer
"What you think today is what you live tomorrow"
jgcode
Active Participant
Active Participant
on

Hi FraggerFox

Just to clarify - there is no mention of OpenG in the above document.

Actually, this package has no code dependencies.

The only dependency is the JGCODE Library Palette and you only need that if you want to expose it in the palettes (recommended).

I decided to release the code as a package (.vip/.ogp) as IMHO (and many others) this is a superior format for LabVIEW code distribution.

Anyways VIPM rocks! And its free - so what are you waiting for?

The LabVIEW Tools Network is also package-centric and has just kicked off - so I can't wait until packages go mainstream. I'm excited!

Cheers

-JG

Certified LabVIEW Architect * LabVIEW Champion
jgcode
Active Participant
Active Participant
on

Just to follow-up (not that it changes any of the above)....

This source code for this example does use OpenG VIs but all the supporting VIs are included in the distribution (so OpenG packages are not required and are not dependencies).

These are obviously re-namespaced so there will be no cross-linking etc... with installed OpenG packages

I thought it would be best to mention that - because OpenG rocks too

Anyways, here is the lowdown on packages straight from NI:

NI has adopted and backed the package format (which is the format used by VIPM) as the standard for distributing code on the LabVIEW Tools Network.

Cheers

-JG

Certified LabVIEW Architect * LabVIEW Champion
FraggerFox
Active Participant Active Participant
Active Participant
on

Hi Jonathon,

Seems to be a nice code, but our company prohibits use of open source, so sadly I won't be able to try it

-FraggerFox!
Certified LabVIEW Architect, Certified TestStand Developer
"What you think today is what you live tomorrow"
jgcode
Active Participant
Active Participant
on

Document v14

- Final Entry (before deadline)

Document v15

- There is a code-only version that you can now download if you prefer.

- Please note: the example code has not changed, it has only been uploaded in a different format due to requests.

- Although not part of the original entry, I thought it best to centralise it here.

Certified LabVIEW Architect * LabVIEW Champion
moka520
Member
Member
on

Found out that under LV2013 building an executable fails with error code 1055 if the Error Logger is used. Application builder can not specify which vi has caused the error.

Under developement system it runs just fine.

Contributors