Can you redirection the console log to a file which can be read in Javascript ?

ColinThomas

Member
Hi,

I know that you can redirect the console log to a file, by typing the following in the Process Console

log -f=/filePath/file.log

There running a javascript from the script editor....

and closing the file from the Process Console using

log --close

This will create a file like:

[2020-05-03 14:11:25] ************************************************************
[2020-05-03 14:11:25] PixInsight Core 01.08.06.1457 Ripley (x64)
[2020-05-03 14:11:25] ************************************************************
[2020-05-03 14:11:52]
[2020-05-03 14:11:52] run --execute-mode=auto "/Users/colin/Desktop/PixInsight_Scripts/NewScriptFile6.js"
[2020-05-03 14:11:52]
[2020-05-03 14:11:52] Processing script file: /Users/colin/Desktop/PixInsight_Scripts/NewScriptFile6.js
[2020-05-03 14:11:52] Hello World
[2020-05-03 14:11:52]

which can capture the javascript output.

Is it possible to facilitate this sort of logging from Javascript directly, (or give javascript access to the Process Console in some other manner). I would like the Javascript to monitor the output of a given process and vary an input to it until a desired output parameter is achieved..

Any pointers welcomed.

Clear skies and stay safe


Colin
 
Hi Colin. Do the following:

JavaScript:
console.beginLog();

// do your stuff

File.writeTextFile( "/path/to/logfile.log", console.endLog().toString() );

You can find a real-world example of this in the WeightedBatchPreprocessing.js script file.
 
Hi Juan,

Many thanks: much appreciated especially of the speedy reply..

A javascript of :

console.beginLog();
console.writeln("Hello World");
console.writeln("Hello World123");
File.writeTextFile( "/Users/colin/logfile.log", console.endLog().toString() );

Is creating a file with:

[2020-05-03 17:30:04] ************************************************************
[2020-05-03 17:30:04] PixInsight Core 01.08.06.1457 Ripley (x64)
[2020-05-03 17:30:04] ************************************************************
[2020-05-03 17:30:04] Hello World
[2020-05-03 17:30:04] Hello World123

:cool:

I'll see what I can do in getting some loops to iterate a process to auto-tune parameters.

I'll also add this to the Javascript user documentation that I pointed to in thread:


Clear skies and stay say

Colin
 
Hi Colin. Do the following:

JavaScript:
console.beginLog();

// do your stuff

File.writeTextFile( "/path/to/logfile.log", console.endLog().toString() );

You can find a real-world example of this in the WeightedBatchPreprocessing.js script file.
Juan,

Have you considered allowing the output file to be specified in the beginLog() call? Assuming occasional flushes, this would allow users to more easily monitor and review execution of very time-intensive scripts like WBPP while they are still running. The built-in console window only holds a limited buffer, and also the user experience is poor because scrolling resets each time new data is logged.

John
 
Back
Top