Customize Logging to a Text file

Post any question you may have in regards to GoAnywhere Director and let our talented support staff and other users assist you.
3 posts Page 1 of 1

emaestas

User avatar
Posts: 3
Joined: Wed Sep 23, 2015 12:16 pm

Post by emaestas » Thu Sep 24, 2015 9:14 am
I need to know if it is possible to write out a custom log to a text file. We need to write out to text file with messages about the processing of the tasks in the Job outside the technical log that is generated by the execution of the job.
Example:
If the job finds the files as expected -> Log out SUCCESS: # files delivered, list of files delivered.
If the job doesn't find the file -> Log out ERROR: File name; Reason (file not found, multiple files were found, etc)

The log would be appended as each step of the file retrieval is completed.

Support_Tim

Posts: 35
Joined: Mon Dec 01, 2014 10:35 am

Post by Support_Tim » Thu Sep 24, 2015 1:01 pm
Hello Emaestas,

Yes, it is possible.

Below you will see an example I created for this. It uses the Number of Files Copied variable ${fileCopyCount} and Destination Files variable ${destFiles}. These are specified on the Output Variables tab within a file creation task like Copy, Put or Get.

To put this to a log, used the Print Task found in the Miscellaneous folder and specify an output file on the Advanced tab. To get a list of files, a for-Each loop is used here to “print” the content of ${destFiles}. I want to append the file each time through the loop to create a list, but I want to have a new file each time I run the project. This is why I first create a header in the file and specify “false” in the Append field in my first Print task, then append by choosing “true” in the for-Each loop. I then append a footer to the file after the loop to add in ${fileCopyCount}.

The resulting FileInfoLog.txt file is created in the workspace (temp folder) and then copied to a permanent location after the log is completed. This creates a new file each time and renames it in the permanent folder if the is another already there. See output below.

I think this example should give you the parts you need to assemble your log as you wish.


Project XML:

<project name="Log File Info" mainModule="Main" version="2.0">
<description>Print File info to log</description>

<module name="Main">

<createWorkspace version="1.0" />


<createFileList fileListVariable="fileList" version="1.0">
<fileset dir="C:\Program Files\Linoma Software\GoAnywhere\userdata\documents\tmccall\">
<wildcardFilter>
<include pattern="*.csv" caseSensitive="false" />
</wildcardFilter>
</fileset>
</createFileList>


<copy sourceFilesVariable="${fileList}" destDir="C:\Program Files\Linoma Software\GoAnywhere\userdata\documents\tmuser" numFilesCopiedVariable="fileCopyCount" destinationFilesVariable="destFiles" version="1.0" />


<print file="FileInfoLog.txt" append="false" version="1.0">
<![CDATA[Success! Here is the list of files copied:

]]>
</print>

<forEachLoop itemsVariable="${destFiles}" currentItemVariable="curFile">

<print label="Print Current File" file="FileInfoLog.txt" append="true" version="1.0">
<![CDATA[ ${curFile}
]]>
</print>

</forEachLoop>

<print file="FileInfoLog.txt" append="true" version="1.0">
<![CDATA[

Number of Files Delivered: ${fileCopyCount}]]>
</print>


<copy sourceFile="FileInfoLog.txt" destDir="C:\Program Files\Linoma Software\GoAnywhere\userdata\documents\tmccall" whenFileExists="rename" version="1.0" />


<deleteWorkspace version="1.0" />

</module>

</project>



Output:

Success! Here is the list of files copied:

C:\Program Files\Linoma Software\GoAnywhere\userdata\documents\tmuser\fileList 4.csv
C:\Program Files\Linoma Software\GoAnywhere\userdata\documents\tmuser\fileNames 4.csv
C:\Program Files\Linoma Software\GoAnywhere\userdata\documents\tmuser\servicePermissions 4.csv
C:\Program Files\Linoma Software\GoAnywhere\userdata\documents\tmuser\SvcPermHeader 4.csv


Number of Files Delivered: 4

emaestas

User avatar
Posts: 3
Joined: Wed Sep 23, 2015 12:16 pm

Post by emaestas » Thu Sep 24, 2015 1:11 pm
Thanks for the Example!
I also have found that the Print task w/the If condition will also give me the ability to produce the text file that we are trying to accomplish.
3 posts Page 1 of 1