Question
· Jul 22, 2021

What is Assert event type in Event Log view and How to utilize it?

Hi,

In Event Log there is Assert event type along with Error, Warning, Alert, Trace and Info types. What is Assert event type in Event Log view and What is the use in production?

 

Thanks

Discussion (4)1
Log in or sign up to continue

Here's an example:

Class User.Assert Extends Ens.BusinessProcess [ ClassType = persistent, Language = objectscript ]
{

Method OnRequest(pRequest As Ens.Request, Output pResponse As Ens.Response) As %Status
{
    Set pResponse = ##class(Ens.Response).%New()
    
    $$$LOGINFO("$$$ASSERT(1)")
    $$$ASSERT(1) // skipped
    
    $$$LOGINFO("$$$LOGASSERT(1)")
    $$$LOGASSERT(1)
    
    $$$LOGINFO("$$$ASSERT(0)")
    $$$ASSERT(0)
    
    $$$LOGINFO("$$$LOGASSERT(0)")
    $$$LOGASSERT(0)

    Quit $$$OK
}
}

$$$ASSERT(condition) Writes an entry of type Assert, if the argument is false. condition is an ObjectScript expression that evaluates to true or false.

$$$LOGASSERT(condition) Writes an entry of type Assert, for any value of the argument. condition is an ObjectScript expression that evaluates to true or false.

so in the same way that you would have a $$$LOGERROR() statement in your code or a $$$TRACE the $$$ASSERT AND $$$LOGASSERT() will write to ^Ens.Log.UtilD in the case of $$$Assert()

The exact code for each is defined in the Ensemble.inc Include file

#define ASSERT(%condition) If '(%condition) { $$$LOGASSERT("Assert Condition Failed: "##quote(%condition)$char(13,10)) BREAK }

#define LOGALERT(%arg) Do ##class(Ens.Util.Log).LogAlert($$$CurrentClass,$$$CurrentMethod,%arg)

interesting: the $$$$ASSERT has a BREAK statement in it.

so if you have BREAK L/L+/S/S+ then if the task is running in the fore ground then it will automatically BREAK at that point.

If the Production item is not running in the foreground the BREAK will be ignored.

It's basically the same as saying 'If condition $$$LOGINFO("message")' I suspect it is probably useful in BPL's where to write an IF construct is tedious in comparison with a single statement $$$.... in ObjectScript