Dr. Maison & Partner GmbH announces the immediate availability of the free Log-Plugin for Servoy. The Log-Plugin wraps the powerful log4j logging technology into a simple plugin. If your code looks like this, the Log-Plugin will be your friend:
// application.output('entering loop');
for ( var i = 1 ; i <= foundset.getSize() ; i++ )
{
var record = foundset.getRecord(i);
// application.output('got record ' + i);
if (record.someField > someValue) {
// application.output('someValue is smaller than someField for record ' + i);
}
}
The Log-Plugin allows developers to create outputs to the console or a log file without the need to uncomment these outputs for deployment. With the Log-Plugin you can easily control what you want to have outputted at what time. This simple code example demonstrates how the Log-Plugin works:
// Set the Level from which on messages are outputted
plugins.Log.debugLevel = 'INFO';
// Create a log file to enable logging to a file
plugins.Log.logFilePath = 'C:\\test.log';
// Set the output pattern
plugins.Log.outputPattern = '%s %p %d{HH:mm:ss.S}: %m%n';
// Output some messages
plugins.Log.trace('This is a trace message'); // Will not be outputted if debugLevel is 'INFO'
plugins.Log.debug('This is a debug message'); // Will not be outputted if debugLevel is 'INFO'
plugins.Log.info('This is a info message');
plugins.Log.warn('This is a warn message');
plugins.Log.error('This is a error message');
plugins.Log.fatal('This is a fatal message');
The warn message above appears in the log as (how things get written is controlled by the output pattern):
solutionName WARN 18:10:00.484: This is a warn message
The debugLevel controls, what gets outputted. A debugLevel “WARN” will prevent all “TRACE”, “DEBUG” and “INFO” messages from being written to the console or a log file. So the code example above could look like
plugins.Log.trace('entering loop');
for ( var i = 1 ; i <= foundset.getSize() ; i++ )
{
var record = foundset.getRecord(i);
plugins.Log.trace('got record ' + i);
if (record.someField > someValue) {
plugins.Log.debug('someValue is smaller than someField for record ' + i);
}
}
Only for debugLevel = “TRACE” you will see “entering loop” and “got record i”. Maybe more interesting is to know if (record.someField > someValue), so the priority of that message is “DEBUG”. If you know what is going on exactly, you simply set the debugLevel to “TRACE”. At deployment, you might want to set the debugLevel to “ERROR”, so only errors will be outputted.
The Log-Plugin can currently output to the console (or the client’s Java trace file), a log file of your choice (you can provide a path) or the server log file. More output options are possible (e.g. writing to a database table). i18n message keys are supported. You can control the way messages are outputted by providing an output pattern (see example above). You can also provide a debugLevel from that on messages are written to the status area of your solution as text or warning (displays in red). There is no (and will not be) documentation, but all methods have tooltips and sample code.
The Log-Plugin is provided as is and can be freely downloaded from http://www.servoy-plugins.de.
If you have any questions, bug reports, feature wishes, ideas or just want to comment how great you think the plugin is, please send a message to plugins@maison-partner.de
Patrick