Logging messages to a Log table
Posted 08 March 2012 - 08:47 AM
Log($msg, $severity, $user...) // adds a timestamped log message to the log table with given severity
PerformScript("$msg=\"Bad error occurred in XXXX\" ; $severity=\"Error\" ; $user=\"" & Get(CurrentUser)& "\";")
However, the actual script is not very fast or efficient, as it basically does this:
* create a new window showing the log table (or show it if it's already open)
* create a new record in the log table
* fill in the fields
* close or hide the log window
The reason that I use a separate window for the log table, rather than simply using "go to layout "Log" ; ... ; Go to layout (original layout)" is that I've found that switching layouts can cause some issues (tab panel tab is lost, portals lose their scroll position, etc.) Also, this means I can call the script from anywhere, even if the current table doesn't have a relationship to the log table.
Question: is there a better way? I was wondering if there was some clever way to get the same result without switching windows or layouts?
Posted 08 March 2012 - 10:09 AM
Posted 08 March 2012 - 03:11 PM
Please post questions to the Forum, not directly to me. Back-up your files before making changes!
Whenever I hear the term "popular culture" I reach for my Iridium Q-36 Space Modulator.
Posted 09 March 2012 - 10:38 AM
Try using a "magic key" method to create related records. This works through a global field and does not require changing layouts.
Very cool : reading this, I had some questions.
* Can this be used from any layout? Or does it need to be run from a layout that has the g_magic_key relationship? If so thats a little limiting compared to my scripted version (which has the advantage that it can be called from anywhere).
* Is this multi-user safe? It should be since it uses globals.
* Is this single-user recursive safe? I'm guessing it's not, since the global key value would be the same for a single user. (The scenario I'm imagining is an error that happens in the logging code itself, so that the logging code tries to log an error in the middle of logging a message. Probably not a big problem.)
Posted 09 March 2012 - 09:24 PM
Be carefull when designing this; specifically look out for creating an infinite loop in your script.
the logging code tries to log an error in the middle of logging a message