michael_madsen
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("Scrip ting.FileS ystemObjec t");
var strLogfilename = GetLogDirectory() + "\\" + GetLogFilename();
var objLogFile = objFso.OpenTextFile(strLog filename, ForAppending, true);
objLogFile.WriteLine(strDa te + " " + "[" + 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 ()->GetUse rRecordSet () 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.
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("Scrip
var strLogfilename = GetLogDirectory() + "\\" + GetLogFilename();
var objLogFile = objFso.OpenTextFile(strLog
objLogFile.WriteLine(strDa
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER