Copy link to clipboard
Copied
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?
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();
}
Copy link to clipboard
Copied
I don't know the answer, but I'm curious as well.
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
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");
Copy link to clipboard
Copied
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:
Uwe
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more