Following script adds a record to msglog. If for some reason the message could not be written to msglog it is printed on screen and in sc.log

Code:
// Add a message to msglog

//MessageAdd("msgClass", "msgName", "device", 1, 1, ["msgText","line 2"])


function MessageAdd(msgClass, msgName, device, msgLevel, msgNumber, msgText)
{
	var msglogFile = new SCFile("msglog");

	msglogFile.msg_class = msgClass;
	msglogFile.msg_name = msgName;
	msglogFile.device = device;
	msglogFile.msg_level = msgLevel;
	msglogFile.msg_number = msgNumber;
	msglogFile.msg_text = msgText;
	msglogFile.operator = system.functions.operator();
	msglogFile.msg_time = system.functions.tod();

	var rc = msglogFile.doInsert();
	if ( rc != RC_SUCCESS )
	{
		print("ERROR:");	
		print("***** ERROR: Failed to add record to msglog: ("+rc+") "+RCtoString(rc));	
		print("     msgClass: "+msgClass);	
		print("     msgName: "+msgName);	
		print("     device: "+device);	
		print("     msgLevel: "+msgLevel);	
		print("     msgNumber: "+msgNumber);	
		print("     msgText: "+msgText);		
	}
}