This tutorial describes how to set up a Log Engine client.
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.
Create a custom class CMyLogEngine
Declare the members CLogClient, CLogViewEvent, CLogViewRecent and CLogFilter in the header file of the client application
Declare ConstrucL() function in the header file of the client application
Implement ConstructL() function
Establish a connection to the Log Engine
get the log events using CLogViewEvent
get the log of recent events using CLogViewRecent
add a log filter using ClogFilter
The client applications can use the log events to be displayed to the user or for other used as a data for further processing.
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.