Adding logged errors to a property list/report

For the purpose of reporting on the run of a masterscript, how can I get the logged errors into a property list in order to see the errors under a failed script in the results and where should I call on the property list? Also, how can I control the formatting of a list? I would like to get rid of the parenthesis and clean up the commas as well.

Currently the report reads like so:
------------------------------------------------------
Test results from 02/26/18, 09:48 AM:

Successes:
(Mode_to_Windows_Desktop
, Windows Login)

Failures:
(Windows Verify Folders
, Windows Web)
------------------------------------------------------

I want to see the logged errors for why Windows Verify Folders and Windows Web are failed.

Code is as follows:

Set myScripts to (Script1,Script2,Script3,Script4)

set successes to ()
set failures to ()

repeat with each item currentScript of myScripts
     RunWithNewResults currentScript
     Set currentResult to the result
     
     If currentResult's status is "success"
          insert currentScript & return after successes
     else if currentResult's status is "Failure"
          Insert currentScript & return after failures
     end if
end repeat

//Log results
Log "Successes:" && successes & return
if failures is empty
     Log "Failures:" && "None
else
     LogError "Failures:" && failures & return
end if

#Below was intended for an email, but Im just dumping it to a file
Set body to "Test results from " & the date & comma & the time & colon & return & return & "Successes: " return & successes & return & return "Failures: " return & failures

put body into file "~/Desktop/Windows_Desktop_Results.





Comments

  • nathan_dangernathan_danger Member
    Hey Nate!
    Good job so far! Im still digging into getting the logged errors rolled into the report, but I figured out your formatting problem! Just put the following line right above where you set successes and failures to ():

    set the listFormat to (prefix:" ",seperator:return,suffix:" ")

    now your report will print like this:

    Test results from 02/26/18, 09:48 AM:

    Successes:
    Mode_to_Windows_Desktop
    Windows Login

    Failures:
    Windows Verify Folders
    Windows Web


    Classy!!!
  • nathan_dangernathan_danger Member
    Problem solved!!! I copied each scripts log file to a folder, then used the files() function for that folder to generate a list of files. Then I iterated through each file looking for logged errors which were output to a file and a variable for writing. Then all logged errors are displayed in the report from my master script. Changes in bold.


    Set myScripts to (Script1,Script2,Script3,Script4)

    set successes to ()
    set failures to ()
    set mylogs to ()
    set problems to ()

    repeat with each item currentScript of myScripts
         RunWithNewResults currentScript
         Set currentResult to the result
         
         If currentResult's status is "success"
              insert currentScript & return after successes
         else if currentResult's status is "Failure"
              Insert currentScript & return after failures
              put the logfile of the last item fo scriptResults(currentScript) into mylogs
              copy file the logfile of the last item of scriptResults(currentScript) as "~/Desktop/MyLogs"&currentScript
         end if
    end repeat

    set logtest to files("~/Desktop/MyLogs")
    repeat with each item currentfile of logtest
         repeat with each line x of file currentfile by reference
              if item 2 delimited by tab of x contains "Log Error" then
                   insert "Potential LCR:"&& item 4 delimited by tab of x && "|" && item 7 delimited by tab of x && return after problems

    //Log results
    Log "Successes:" && successes & return
    if failures is empty
         Log "Failures:" && "None
    else
         LogError "Failures:" && failures & return
    end if

    #Below was intended for an email, but Im just dumping it to a file
    Set body to "Test results from " & the date & comma & the time & colon & return & return & "Successes: " return & successes & return & return "Failures: " return & failures &return & return "Errors: " return & problems

    put body into file "~/Desktop/Windows_Desktop_Results.

Sign In or Register to comment.