Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Jun 22, 2015 Jun 22, 2015

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?

TOPICS
Scripting
6.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Jun 22, 2015 Jun 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();

}

Translate
Adobe
Community Expert ,
Jun 22, 2015 Jun 22, 2015

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 22, 2015 Jun 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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 22, 2015 Jun 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();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 23, 2015 Jun 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");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 23, 2015 Jun 23, 2015
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines