Forum Discussion

hhagay's avatar
hhagay
Contributor
9 years ago

How to build a dynamic report method that count through function calls and gets function name

Hello

 

I am implementing the following around every function call

 

 

	/**
	* Function Name:beginlog
	* Description:
	* @param {}
	* @return {}
	*/
function beginlog(StepDescription)
{
    Log.AppendFolder(StepDescription);
    Indicator.PushText(StepDescription);
}
	/**
	* Function Name:endlog
	* Description:
	* @param {}
	* @return {}
	*/
function endlog()
{
    Indicator.PopText();
    Log.PopLogFolder();
}

 

Questions:

1. Is there a way to get the function name dynamically?

2. Is there a way to maintain a Global array that numerates the various beginlog() calls?

3. Is there a way to hold a Global getCurrentTime instead of passing it to every script?

 

Thank you  :)

 

 

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Hrm... that code looks familiar... ;)

     

    If I understand this correctly... you want some way that, whenever beginlog is called, you keep track of it in some array including a time stamp of when it happened.

     

    Here's what I threw together real quick:

     

    function GeneralEvents_OnLogCreateNode(Sender, LogParams)
    {
        Log.Message('Does this work? ' + aqConvert.DateTimeToFormatStr(aqDateTime.Time(), '%H:%M'));  
    }
    
    function test(){
    
    TestLogUtils.beginlog('just checking');
    TestLogUtils.beginlog('checking again');
    TestLogUtils.endlog();
    TestLogUtils.endlog();
    
    }

    I'm using the OnLogCreateNode event handler which fires every time a folder is created in the Log (that's what AppendFolder does). I'm using a combination of aqDataTime and aqConvert to time stamp it as well.

    So... probably some sort of implementation of that event handler which would write out too a global variable or array every time begin log is called with the text of what was called and the time stamp...

    Does this help?

    P.S. Please attribute the code if you go forward with this as per the Creative Commons license.  Thanks!

     

     

     

    • hhagay's avatar
      hhagay
      Contributor

       

      Will definitely share the code with the community :)

       

      Question:

       

      How do I get the name of the function that I am currently running (hence executing its beginlog)?