Example of logging using Action code functions (v9.1+)

Another demo by @eastgate

xlogs-2.tbx (113.3 KB)

What it does:
Adds functions for writing diagnostic messages to a log note. This is extremely helpful for gaining insight into what your functions are doing.

Techniques:

  • Defining functions
  • Manipulating styled text

Look at note /Hints/Library/Logs Library in the TBX.

To try it yourself:

See the bottom lines of the code; these exercise the functions and write specimen logging to note /Logs in the same TBX.

The “Logs Library” is essentially a self contained ‘library’ of functions that can be copied to other TBX and used the same ways. Once you’ve seen the logs working, you might to well to comment out the example calls at the bottom of the note (by starting the line with //. That way you can refer to them for a reminder of how to call the logging functions but not actually have them execute.

A meta-demo in this is the notion of being able to take a library note from one TBX and place it in another. Note that if you do similar with your own library notes and these interact with user attributes, it is suggested you add a comment to the function indicated the attributes needed (and their data type, default, etc.).

2 Likes

Maybe it is a good idea to think about namespaces - my first functions were a log lib too - so reusing your code may result in a conflict because of several functions sharing an identical name. So instead of

function ClearLog(){...}

maybe
function ClearLog_MA(){...} or MA_ClearLog(){...}

is the way to go?!

Yes! In fairness, @eatgate wrote this to test/demonstrate logging.

It strikes me that this—logging—is something the community here can polish a lot. My only proviso is that the hi-tech folk remember that many—most? Tinderbox users aren’t programmers or computer scientist, nor do they aspire to be. So, likely we want two sets of loggers: one for the programmers and one for folk who don’t get programming. No judgment implied in that description, just different strokes for different folks.

Love this logging demo. You may find my new training video on functions helpful: Tinderbox Training Video 62- Dynamically create notes from attributes with functions.