...

View Full Version : Logging in my ASP pages



ellisd5
12-13-2004, 04:52 PM
I've written this function but it doesn't work :confused:
With this code not in a Function but directly in a asp page it works, however if I call it in my asp page using logger("My message") it fails.

Im pretty new to ASP and noticed in the other couple of functions I always set the function to return a value, do I need to do this? I don't want it to return anything, i just want it to write to the log.


Function logger(logMessage)

'' Enter login into log
Dim objFSO, filename
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
filename = Server.MapPath(".") & "\logs\logBook.log"

Dim objTextStream
Set objTextStream = objFSO.OpenTextFile(filename, 8)

objTextStream.WriteLine(now & " - " & logMessage)
objTextStream.Close

Set objTextStream = Nothing
Set objFSO = Nothing

End Function

ghell
12-13-2004, 10:07 PM
hmm i get this problem too, i dont know if no value is returned, sometimes it works and sometimes it doesnt (i tried makein a cdosys function similar to the php mail function)

but it might work if u use a sub instead .. i hardly use subs at all so im not sure

ellisd5
12-14-2004, 11:22 AM
i see, so whats a sub?

More from a java background trying to get to grips with ASP?

Roelf
12-14-2004, 11:41 AM
a sub is a subroutine, like a function with no return value. In your case:

Sub logger(logMessage)

'' Enter login into log
Dim objFSO, filename
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
filename = Server.MapPath(".") & "\logs\logBook.log"

Dim objTextStream
Set objTextStream = objFSO.OpenTextFile(filename, 8, True)

objTextStream.WriteLine(now & " - " & logMessage)
objTextStream.Close

Set objTextStream = Nothing
Set objFSO = Nothing

End Sub

I made a little addition to the code, in case the file cannot be found, the true argument of the opentextfile function will create the file for you

ellisd5
12-14-2004, 12:00 PM
I See, thanks for the knowledge.

Still not working for some reason, made a massive mistake being I have the Sub in a include file and forgot to include it so that didn't help.

Got it included now but it still dont work. Is there a special way in which I should call the Sub? At the moment i just doing....
logger("My message")
Also, how do you debug in ASP? in java i would print out message's to the console to see what's happening, can I do anything like that? I don't have any special programmes, just using a text editor and uploading to server to test this.

ghell
12-14-2004, 12:41 PM
subs are called without parenthesis

logger "some text"

i think you can do
Call logger "some text"
but i cant really remember

edit: i was looking for similar error catching and found this http://members.optusnet.com.au/~mrjolly/ im not really sure how good it is but it seems pretty nice.. i do miss my java try catch blocks though :(

ellisd5
12-14-2004, 12:51 PM
I got it working now, thanks to all that helped me.

I such a fool, made a massive schoolboy error, forgot to put the <% %> in the include file :mad:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum