Link to home
Start Free TrialLog in
Avatar of michael_madsen
michael_madsenFlag for Denmark

asked on

Getting a calleer list from JScript

I am writing an ASP project (with JScript - NOT VBScript)
I am about to write a simple file-log for the project.
So far it just enables me to write something to a text-file, by inserting one line into the code (where you wan't something logged):

      WriteToLog ("Something has happended");

Now the WriteToLog function itself is very simple like this:

      function WriteToLog(strText) {
            var strDate = GetDateTimeString();
            var strSessionId = Session.SessionID;

            var ForAppending = 8;
      
            var objFso = Server.CreateObject("Scripting.FileSystemObject");
            var strLogfilename = GetLogDirectory() + "\\" + GetLogFilename();
            var objLogFile = objFso.OpenTextFile(strLogfilename, ForAppending, true);
            objLogFile.WriteLine(strDate + "   " + "[" + strSessionId + "]" + "   " + strText);
            objLogFile.Close();
      }  // WriteToLog()

This results in something like this in the log-file:

      2006-06-07 11:38:27,670   [858642225]   Something has happended

What I would like it to add to this, is the entire path of function calls. Let me explain it better with an example:

Let's say that the webpage we are retrieving is called showuser.asp?uid=1234
This page calls a function (in an included page) called GetUserById()
The GetUserById function calls another function called GetAllUsers()
The GetAllUsers function calls another function called GetUserRecordSet()
The GetUserRecordSet function is the function that issues the WriteToLog call.
Now I would like the WriteToLog to trace the call backwards to show all the callers, like this:

      2006-06-07 11:38:27,670   [858642225]   GetUserById()->GetAllUsers()->GetUserRecordSet()   Something has happended

I imagine that this is somehow possible through the Function object's caller property, but I can't figure out how to do it.
ASKER CERTIFIED SOLUTION
Avatar of wranlon
wranlon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of michael_madsen

ASKER

wranlon: Very nice (and quick) solution. I have removed the attributes list (as I don't need them).