So, two functions: one to create a new log, the other to write statements to it:
Code: Select all
// create a new log file in logs directory with time stamp in its name
function newLog() {
var logName = '../logs/my_process_'+DateServices.formatDate(system.getVariables().$SYSTEM_DATETIME.value, "dd-MM-yyyy-HH-mm")+'.txt';
FileServices.createNewFile(logName);
return logName;
}
// write to log file
function writeLog(logName, message, messageType) {
var m = FileServices.readFile(logName);
m = m + DateServices.formatDate(system.getVariables().$SYSTEM_DATETIME.value, "ddMMyyyy:HHmm")+" "+messageType+" "+ message + '\n';
FileServices.writeFile(logName, m);
}
Code: Select all
var logName = newLog();
writeLog(logName,'Starting my process...','INFO');
writeLog(logName,'Ending my process...','INFO');
Code: Select all
21052014:1040 INFO Starting my process...
21052014:1040 INFO Ending my process...