Forum Discussion

MarkSchofer's avatar
MarkSchofer
Frequent Contributor
3 years ago
Solved

A Log That Readable and is Pleasant to Read

I write to one file when an error happens another when it works as expected.  
1. How do I programmatically purge the data.   or

Or can I read a nextvalue from a sequence or Insert a date time stamp so it is unique.

******oFile.Write(aqDateTime.Now())*****
2. How do I add a carriage return so the file is not all one line.

I am using Python

if DateCheck == 'Y':
#aqFile.WriteToTextFile("C:\Users\Schofem\CheckChecks.txt", "One", aqFile.ctANSI)
oFile = aqFile.OpenTextFile("C:\\Users\\Schofem\\Logs\\CheckChecks.txt", aqFile.faWrite, aqFile.ctANSI, False)
oFile.Write(DDT.CurrentDriver.Value[0])
oFile.Write(" - ")
oFile.Write(DDT.CurrentDriver.Value[26])
oFile.Write(" - ")
oFile.Write(DDT.CurrentDriver.Value[27])
oFile.Write(" - ")
oFile.Write("PassedDateCheck")
oFile.Write("The Test")
oFile.Close()
# else:
#aqFile.WriteToTextFile("C:\Users\Schofem\CheckChecks.txt", "One", aqFile.ctANSI)
# oFile = aqFile.OpenTextFile("C:\\Users\\Schofem\\BadChecks.txt", aqFile.faWrite, aqFile.ctANSI, False)
# oFile.Write(DDT.CurrentDriver.Value[0])
# oFile.Write(" - ")
# oFile.Write(DDT.CurrentDriver.Value[26])
# oFile.Write(" - ")
# oFile.Write(DDT.CurrentDriver.Value[27])
# oFile.Write(" - ")
# oFile.Write("FailedDateCheck")
# oFile.Write("The Test")
# oFile.Close()

 

5 Replies

  • MarkSchofer's avatar
    MarkSchofer
    Frequent Contributor

    Marsha Thank You Very much. It is still reading on one line.   However much improved. Thanks

    # fOR AWHILE THIUS WAS THE NEW AND IMPROVED METHOD
    # For #2, you can use WriteLine instead of Write -MARSHA
    # #aqFile.WriteToTextFile("C:\Users\Schofem\CheckChecks.txt", "One", aqFile.ctANSI)
    # oFile = aqFile.OpenTextFile("C:\\Users\\Schofem\\Logs\\CheckChecks.txt", aqFile.faWrite, aqFile.ctANSI, False)
    # oFile.Write(DDT.CurrentDriver.Value[0])
    # oFile.Write(" - ")
    # oFile.Write(aqDateTime.Now())
    # oFile.Write(DDT.CurrentDriver.Value[26])
    # oFile.Write(" - ")
    # oFile.Write(DDT.CurrentDriver.Value[27])
    # oFile.Write(" - ")
    # oFile.Write("PassedDateCheck")
    # oFile.Write("The Test")
    # oFile.Close()
    sPath = "C:\\Users\\Schofem\\CheckChecks.txt" ******Note to those those scoring at home. Need the double forward slashes 
    # Creates a text file at the specified location
    aqFile.Create(sPath)
    # Opens the created file for writing
    myFile = aqFile.OpenTextFile(sPath, aqFile.faWrite, aqFile.ctUnicode)
    # Writes text to the file
    myFile.WriteLine(aqDateTime.Now())
    myFile.WriteLine(DDT.CurrentDriver.Value[0])
    myFile.WriteLine(DDT.CurrentDriver.Value[26])
    myFile.WriteLine(DDT.CurrentDriver.Value[27])
    # Closes the file
    myFile.Close()

    • Marsha_R's avatar
      Marsha_R
      Champion Level 3

      Hm I would have thought that had a <CR> in it.  You could try writing out a <CR> or <CR><LF> after the line and see what it does.