-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlog.js
65 lines (62 loc) · 1.78 KB
/
log.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* A console for ExtendScript
* Bruno Herfst 2017
*/
var console = {
settings : {
writeToFile : true,
writeToConsole : true
},
logFile : (function() {
var sName = File($.fileName).name;
var sPath = File($.fileName).path;
var lastPeriod = sName.lastIndexOf(".");
if (lastPeriod > 0) { // Ignore hidden files
sName = sName.substr(0, lastPeriod);
};
return File( sPath + "/" + sName + ".log");
})(),
write : function( msg ) {
this.logFile.open("a");
this.logFile.write(output);
this.logFile.close();
if (this.settings.writeToConsole) {
$.write( String(msg) );
};
},
writeln : function( msg ) {
this.logFile.open("a");
this.logFile.writeln(String(msg));
this.logFile.close();
if (this.settings.writeToConsole) {
$.writeln( String(msg) );
};
},
log : function ( msg ) {
var now = new Date();
var output = now.toTimeString() + ": " + String(msg);
this.writeln( output );
},
alert : function( msg ) {
this.log(msg);
alert(msg);
},
clear : function() {
this.logFile.open("w");
this.logFile.write("");
this.logFile.close();
if (this.settings.writeToConsole) {
if (app.name === "ExtendScript Toolkit") {
app.clc();
} else {
var estApp = BridgeTalk.getSpecifier("estoolkit");
if(estApp) {
var bt = new BridgeTalk;
bt.target = estApp;
bt.body = "app.clc()";
bt.send();
};
};
};
}
};