Setting Up A Log Engine Client

This tutorial describes how to set up a Log Engine client.

Introduction

If you are certain that you are coding for a platform with logging functionality you create a custom class with some such name as CMyLogEngine. It should have members of the classes CLogClient, CLogViewEvent, CLogViewRecent and CLogFilter and an observer of some kind. The functions of your custom class will use the functionality of these classes by calls to the member objects.

If you are not certain that your platform will provide logging functionality you must use a log wrapper framework. Write a custom class to use the log wrapper functionality with some such name as myLogWrapper. It should have two members which own CLogWrapper and CLogClient objects. In the constructor function of myLogWrapper call the ClientAvailable() function of CLogWrapper to determine whether logging functionality is present. If so, construct the CLogClient member: if not, leave. The effect of this is that calls to the log client functionality of myLogWrapper will access an actual log client if the functionality is available. However, if the functionality is not available calls to the log client functionality will either have no effect or else leave as in this example code.

Procedure

  1. Create a custom class CMyLogEngine

  2. Declare the members CLogClient, CLogViewEvent, CLogViewRecent and CLogFilter in the header file of the client application

  3. Declare ConstrucL() function in the header file of the client application

  4. Implement ConstructL() function

    1. Establish a connection to the Log Engine

          iLogClient = CLogClient::NewL(iFs);
    2. get the log events using CLogViewEvent

      iLogViewEvent = CLogViewEvent::NewL(*iLogClient);
    3. get the log of recent events using CLogViewRecent

      iLogViewRecent = CLogViewRecent::NewL(*iLogClient);
    4. add a log filter using CLogFilter

      iLogFilter = CLogFilter::NewL();

Result

The client applications can use the log events to be displayed to the user or for other used as a data for further processing.

Log engine client example

Example code for a Log Engine client on a platform with logging functionality

void CMyLogEngine::ConstructL()
    {
    
    // Establish connection to log engine
    iLogClient = CLogClient::NewL(iFs);
 
    // Log view and view for recent events with standard priority
    iLogViewEvent = CLogViewEvent::NewL(*iLogClient);
    iLogViewRecent = CLogViewRecent::NewL(*iLogClient);

    // Filter for events
    iLogFilter = CLogFilter::NewL();

Example code for a Log Engine client using a wrapper framework

void CMyLogWrapper::ConstructL(RFs& aFs)
     {
     
     // create the CLogWrapper to forward requests to.
     iLogWrapper = CLogWrapper::NewL(aFs);
 
     if (iLogWrapper->ClientAvailable())
         {
         iLogClient = static_cast<CLogClient*>(&iLogWrapper->Log());
         }
     else
         {
         User::Leave(KErrNotSupported);
         }
     }

You can now use myLogWrapper as if it was a log client.