/////////////////////////////////////////////////////////////////////////////// // Object: Logger // Usage: Log information to a text file // Input: String to full path of file to create or append, if no file is given // then output file Logger.log is created on the users desktop // Return: Logger object // Example: // // var a = new Logger(); // a.print( 'hello' ); // a.print( 'hello2\n\n\nHi\n' ) ; // a.remove(); // a.log( Date() ); // a.print( Date() ); // a.display(); // /////////////////////////////////////////////////////////////////////////////// function Logger( inFile ) { // member properties // the file we are currently logging to if ( undefined == inFile ) { this.file = new File( Folder.desktop + "/Logger.log" ); } else { this.file = new File( inFile ); } // member methods // output to the ESTK console // note that it behaves a bit differently // when using the BridgeTalk section this.print = function( inMessage ) { if ( app.name == "ExtendScript Toolkit" ) { print (inMessage); } else { var btMessage = new BridgeTalk(); btMessage.target = "estoolkit"; btMessage.body = "print(" + inMessage.toSource() + ")"; btMessage.send (); } } // write out a message to the log file this.log = function( inMessage ) { if ( this.file.exists ) { this.file.open( 'e' ); this.file.seek( 0, 2 ); // end of file } else { this.file.open( 'w' ); } this.file.write( inMessage ); this.file.close(); } // show the contents with the execute method this.display = function() { this.file.execute(); } // remove the file this.remove = function() { this.file.remove(); } }