Maintaining Log Events

This tutorial describes how to maintain events using Log Engine.

Context

You maintain a log by adding, changing and deleting events with the appropriate calls to the CLogClient member of your application. When you are adding or changing events, the arguments are a CLogEvent and a TRequestStatus object to hold the return value. When you are deleting, they are a CLogEvent and a TLogId.

It is sometimes necessary to create a custom event type. If you want to log events of a custom created event type, you need to initialize a CLogEventType object and add it to the log. You add the event type when you install your application, and delete it if you uninstall the application. You add, change and delete custom event types by calling the appropriate functions of a CLogClient object:

iLogClient->AddEventType(*iLogEventType, iStatus);

iLogClient->ChangeEventType(*iLogEventType, iStatus);

iLogClient->DeleteEventType(aId, iStatus);

The arguments are a CLogEventType (or TUid when deleting) and a TRequestStatus object.

To maintain log events, do the following:

Steps

  1. declare an event as a member of your log client class

    CLogEvent* iCurrentEvent;
  2. initialize the event using its member functions
    iCurrentLogEvent = CLogEvent::NewL();
    ...
    iCurrentLogEvent->SetTime(time);
  3. add an event to a log with the AddEvent() function of a CLogClient object
    iLogClient->AddEvent(*iLogEvent, iStatus);
    AddEvent() creates an asynchronous request and no other asynchronous request must be outstanding when you call it. For this reason, the CLogEvent argument is typically read off a queue of events waiting to be processed.
  4. change an event record with the ChangeEvent() function.
    iLogClient->ChangeEvent(*iLogEvent, iStatus);

Results

Note that it is not possible to change the event type of an event after it has been added to the log.

The events specified by the log engine clients are maintained.

Next actions

You do not normally need to delete an event. A log has a maximum size which the log engine maintains automatically by deleting the oldest events when newly added events would cause the maximum to be exceeded. If you want to delete an event for other reasons you call the DeleteEvent() function. iLogClient->DeleteEvent(aLogId, iStatus);

It is important to know that deleting an event type and deleting the actual events of that type are two separate actions. If you just delete the type and not the events, the events will remain in the log but have no type.

Related concepts

Related tasks