Free Log-Plugin: add logging capabilities to your methods

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

Hi Patrick
This looks like a very useful plugin.
A question, as Servoy V3 now uses log4j for logging, (and has log4j.jar in the lib folder) are we going to have any issues with log4j-1.2.14,jar in your folder under plugins?

THanks for the great contribution.

jars in Servoy/lib will not be transferred to the client. So there is no conflict.

True, but what about when running Developer?

Also, is there a possibility of having rolling logs eg when the logfile hits a certain size it gets renamed and a new file is started, just like the log4j commands

MaxFileSize=500KB
MaxBackupIndex=10

I use developer all day and don’t have any problems.

Yes, rolling logs are possible. Actually, there is already a class that is capable of doing that in the plugin, but I thought I keep it simple at first.

OK. I added that possibility. See here http://forum.servoy.com/viewtopic.php?p=35925

The plugins seems useful but how can I install it on my PC ?

Is there a procedure ?

DomTom :?:

Yes. The procedure goes like this: unzip it and place the drmaison-lib folder, the log.jar and the log.jar.jnlp in Servoy/plugins.