Skip to main content
suneelkv
Known Participant
June 22, 2015
Answered

How to log the ExtendScript Tool Kit console prints to a Text File

  • June 22, 2015
  • 3 replies
  • 6584 views

Hi Chaps,

I want to put prints in my whole Script and take the logs of the script.

To do this I need to log the entire console output to a Text file.


Can somebody please tell me how to write the console output to a log file?

This topic has been closed for replies.
Correct answer jsavage77

Might I suggest placing luda.dall's code in a function.  Then just call the function instead of $.writeln() to log to both the console and the file:

function logMe(input)

{

     var now = new Date();

     var output = now.toTimeString() + ": " + input;

     $.writeln(output);

     var logFile = File("/path/to/logfile.txt");

     logFile.open("e");

     logFile.writeln(output);

     logFile.close();

}

3 replies

jsavage77Correct answer
Inspiring
June 22, 2015

Might I suggest placing luda.dall's code in a function.  Then just call the function instead of $.writeln() to log to both the console and the file:

function logMe(input)

{

     var now = new Date();

     var output = now.toTimeString() + ": " + input;

     $.writeln(output);

     var logFile = File("/path/to/logfile.txt");

     logFile.open("e");

     logFile.writeln(output);

     logFile.close();

}

suneelkv
suneelkvAuthor
Known Participant
June 23, 2015

Just a small change though, we have to append the new text so just changed one line

function logMe(input)

{

     var now = new Date();

     var output = now.toTimeString() + ": " + input;

     $.writeln(output);

     var logFile = File("C:/Suneel_ai_related_work/RSE_10inchScripts/logfile.txt");

     logFile.open("a");

     logFile.writeln(output);

     logFile.close();

}

logMe("Suneel");

logMe("Check 1");

logMe("Check 2");

Community Expert
June 23, 2015

If you are working with an already saved script file, you can point the log to the path of your script as well.

$.fileName

will return the whole path including the name of the saved script.

So its path will be:

File($.fileName).path;

Example for a related log text file:


var logFile = File( File($.fileName).path+"/"+File($.fileName).name+"-"+"log.txt" );

Also see:

CS3 JS: $

Uwe

luca.dall
Participant
June 22, 2015

You can do so:

var saveFile = File("C:\\path_to_myLog\\myLog.txt");

saveFile.encoding = "UTF8";

saveFile.open("e", "TEXT", "????");

saveFile.writeln("This is a Line of my Log");

saveFile.close();

Disposition_Dev
Legend
June 22, 2015

I don't know the answer, but I'm curious as well.