Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Logging in my ASP pages

    I've written this function but it doesn't work
    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.

    Code:
    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
    Dale Ellis
    __________________

  • #2
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    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

  • #3
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    i see, so whats a sub?

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

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    a sub is a subroutine, like a function with no return value. In your case:
    Code:
    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
    I am the luckiest man in the world

  • #5
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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....
    Code:
    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.
    Dale Ellis
    __________________

  • #6
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    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

  • #7
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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
    Dale Ellis
    __________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •