A simple logging method

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Dave
Ebase Staff
Posts: 89
Joined: Mon Sep 10, 2007 11:48 am

A simple logging method

#1

Postby Dave » Wed May 21, 2014 8:46 am

Here's a simple way to create a new log file in tomcat/logs and write error or information statements to it as your process executes:

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);
}
and then use it like this:

Code: Select all

var logName = newLog();
writeLog(logName,'Starting my process...','INFO');
writeLog(logName,'Ending my process...','INFO');
You'll then have a log file called my_process_21-05-2014-10-40.txt in tomcat/logs, with content like:

Code: Select all

21052014:1040 INFO Starting my process...
21052014:1040 INFO Ending my process...
0 x

User avatar
dvanhussel
Ebase User
Posts: 161
Joined: Fri Oct 19, 2007 12:45 pm
Location: Haarlem, the Netherlands

#2

Postby dvanhussel » Thu May 22, 2014 8:31 am

We use some similar functions. With a JavaScript const in a global script we set the loglevel we want for a server. (ERROR, INFO, DEBUG).
This way it's not a problem if some debug logging statements are not removed when moving from staging to production.

This makes debugging (when developing a form) also much more convenient then using the 'Execution log' in the designer.

In a console (we use Linux) this is run:

Code: Select all

tail -f {logfile_name}
This way realtime logging is available when executing a form, even when it's not started from the designer.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#3

Postby Jon » Thu May 22, 2014 2:38 pm

See also this post which describes how to use logging with log4j http://forum.ebasetech.com/forum/viewtopic.php?t=633. This is a much safer approach i.e. no possibility of multi-user locking problems, and will also perform better.
0 x


Who is online

Users browsing this forum: No registered users and 13 guests