UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on June 07, 2014, 05:18:28 AM

Title: WriteToLog (log file) function
Post by: kevin on June 07, 2014, 05:18:28 AM
   WriteToLog function

      This function can be placed throughout a program to drop messages out to disk, common known as a log file.  


      Commands used;  WriteNewFile , OpenNewFile, #Print


[pbcode]

   global WriteToLog_Filename$   =currentdir$()+"MyLogFile.txt"



   WriteToLog("Start Of Log")
   WriteToLog("Hello World")
   WriteToLog("end.")





Psub WriteToLog(Message$)
   
   
      local LogFile$=WriteToLog_Filename$
      local Fh,size
      if fileexist(logfile$)=false
      
            fh=WriteNewFile(LogFile$)
            if fh
               writestring fh,Message$                     
               closefile fh
            endif      
         
      else
      
            size=filesize(logfile$)
            fh=OpenNewFile(LogFile$)
            if fh
               writestringat  fh,size,Message$                     
               closefile fh
            endif      
   
      endif
      
      #print "WriteToLog:"+ Message$
      
EndPsub

[/pbcode]


  Related File links:

     - Load File To String & Save String As File (https://www.underwaredesign.com/forums/index.php?topic=3645.0)
     - Encode File  / Hide File Contents / Xor Encryption (https://www.underwaredesign.com/forums/index.php?topic=4289.0)
     - Buffered file copy (copy data in blocks) (https://www.underwaredesign.com/forums/index.php?topic=3815.0)
     - Scan and Backup Media (Work In Progress) (https://www.underwaredesign.com/forums/index.php?topic=4179.0)