VisiTelcoLog Guide : Logging for event unaware applications

Logging for event unaware applications
Legacy applications and event unaware clients can also use the VisiTelcoLog Service. Using the BasicLog interface and explicit write operations using CORBA Any, an event unaware application can make use of the VisiTelcoLog Service. These applications, however, will not be able to use features such as log filtering, forwarding, and event generation.
The following table describes the VisiTelcoLog Service module and interface names and the log features available for event unaware applications.
In this chapter, the following topics will be explained:
Using the log factory to obtain the log object for event unaware applications.
Writing log records for event unaware applications.
Using the log factory
In order to log, an event unaware application needs to get a reference to the BasicLog from its factory, BasicLogFactory. Apart from creating the basic log object, the factory interface also supports some other basic management operations such as find and list.
Resolving the BasicLogService name gets the BasicLogFactory object reference. In the following code snippet, the application looks for a BasicLog with an ID equal to 100, and if it does not find one a BasicLog is created with size equal to 0 (zero). A size equal to 0 (zero) means that there is no predefined size limit. Note that by setting log size to zero, the log continues to expand till all the disk space is used. Specifying a more meaningful value is recommended.
C++
// get service reference
CORBA::Object_var service =
orb->resolve_initial_references("BasicLogService");

DsLogAdmin::BasicLogFactory_var factory =
DsLogAdmin::BasicLogFactory::_narrow(service);

// find log with id 100
DsLogAdmin::LogId id = 100;
DsLogAdmin::Log_var log = factory->find_log(id);

// if log not created, create log
if( log.in() == NULL )
{
CORBA::ULongLong max_size = 4 * 1024 * 1024;
// max_size=0 (zero) leaves the max log size unbounded.

log = factory->create_with_id(id, DsLogAdmin::wrap,
max_size);
}

DsLogAdmin::BasicLog_var basic_log=
DsLogAdmin::BasicLog::_narrow(log.in());
Java
// get service reference
org.omg.CORBA.Object service =
orb.resolve_initial_references("BasicLogService");

org.omg.DsLogAdmin.BasicLogFactory factory =
org.omg.DsLogAdmin.BasicLogFactoryHelper.narrow(
service);

// find log with id 100
int id = 100;
org.omg.DsLogAdmin.Log log = factory.find_log(id);

// if log not created, create log
if( log == null )
{
long max_size = 4 * 1024 * 1024;
// max_size=0 (zero) leaves the max log size unbounded.

log = factory.create_with_id(id,
org.omg.DsLogAdmin.wrap.value, max_size);
}

org.omg.DsLogAdmin.BasicLog basic_log =
org.omg.DsLogAdmin.BasicLogHelper.narrow(log);
Writing log records
The write_records operation is used to write records to logs. The input parameter for this operation is a sequence of CORBA Any. Each Any in the sequence denotes an individual log record.
If the log is full while writing, then the LogFull user exception is thrown. The exception also contains the number of records written from the original sequence of Anys.
If the log's state is off_duty the LogOffDuty user exception is thrown. If the log's state is locked the LogLocked user exception is thrown. If the log is disabled the LogDisabled exception is thrown.
The following code snippet shows steps to write some TMN events using the write_records operation.
C++
// TMN events
TMN::Event event;
TMN::AttrValChgSeq attrvalchg_info;
TMN::AttrValSeq objcrt_info;
TMN::AttrValSeq objdel_info;
TMN::QoSAlarmInfo qosalrm_info;

// Fill TMN events with some data
misc::forge_event_header(event.header);
misc::forge_attrValChgInfo(attrvalchg_info);
misc::forge_objCrtInfo(objcrt_info);
misc::forge_objDelInfo(objdel_info);
misc::forge_qosAlrmInfo(qosalrm_info);

// Sequence of Anys to be written
DsLogAdmin::Anys anys;
anys.length(4);

// Insert the TMN events into Any Sequence
event.name = (const char*)
"TMN::Events::attributeValueChange";
event.info <<= attrvalchg_info;
anys[0] <<= event;

event.name = (const char*)
"TMN::Events::objectCreation";
event.info <<= objcrt_info;
anys[1] <<= event;

event.name = (const char*)
"TMN::Events::objectDeletion";
event.info <<= objdel_info;
anys[2] <<= event;

event.name = (const char*)
"TMN::Events::qosAlarm";
event.info <<= qosalrm_info;
anys[3] <<= event;

// Write the sequence of Anys to log
basic_log->write_records(anys);
Java
// TMN events
TMN.Event event = new TMN.Event();
TMN.AttrValChgSeqHolder attrvalchg_info =
new TMN.AttrValChgSeqHolder();
TMN.AttrValSeqHolder objcrt_info =
new TMN.AttrValSeqHolder();
TMN.AttrValSeqHolder objdel_info =
new TMN.AttrValSeqHolder();
TMN.QoSAlarmInfo qosalrm_info =
new TMN.QoSAlarmInfo();

// Fill TMN events with some data
event.header = new TMN.EventHeader();
event.info = orb.create_any();
Util.forge_event_header(event.header);
Util.forge_attrValChgInfo(attrvalchg_info);
Util.forge_objCrtInfo(objcrt_info);
Util.forge_objDelInfo(objdel_info);
Util.forge_qosAlrmInfo(qosalrm_info);

// Sequence of Anys to be written
org.omg.CORBA.Any[] anys =
new org.omg.CORBA.Any[4];
for (int i = 0; i < 4; i++)
{
anys[i] = orb.create_any();
}

// Insert the TMN events into Any Sequence
event.name = "TMN::Events::attributeValueChange";
TMN.AttrValChgSeqHelper.insert(event.info,
attrvalchg_info.value);
TMN.EventHelper.insert(anys[0],event);

event.name = "TMN::Events::objectCreation";
TMN.AttrValSeqHelper.insert(event.info,objcrt_info.value);
TMN.EventHelper.insert(anys[1],event);

event.name = "TMN::Events::objectDeletion";
TMN.AttrValSeqHelper.insert(event.info,objdel_info.value);
TMN.EventHelper.insert(anys[2],event);

event.name = "TMN::Events::qosAlarm";
TMN.QoSAlarmInfoHelper.insert(event.info,qosalrm_info);
TMN.EventHelper.insert(anys[3],event);

// Write the sequence of Anys to log
basic_log.write_records(anys);