The following example reads an entry from the default Error Logging log file. It searches for the first (that is, most recent) entry in the file that has a product manufacturer named "IBM" and a severity less than 4.
#define INCL_LOGGING
#include <unidef.h>
#include <os2.h>
#include <stdio.h>
#include <lfdef.h>
#define ERROR_LOG_FILE_ID 1
#define START_AT_FIRST_ENTRY 0
{
ULONG service;
ULONG severity = 4;
ULONG entry_id = 12;
LREREQUEST read_entry_packet;
EVENTKEY EventKey;
BYTE log_entry_buffer¢2048!;
ULONG log_entry_buffer_length;
SUBBLOCK subblock1, subblock2, subblock3;
HEADERBLOCK headerblock1, headerblock2;
FILTERBLOCK filter;
UniChar *manufacturer_name = L"IBM";
service = ERROR_LOGGING_SERVICE;
/* Construct an event notification filter with 2 header blocks. */
/* The first header block points to a single subblock. */
/* The second header block points to a chain of two subblocks. */
filter.packet_size = sizeof(FILTERBLOCK);
filter.packet_revision_number = LF_UNI_API;
filter.header_block = &headerblock1;
/*-------------construct headerblock1---------------------*/
headerblock1.pSubblock = &subblock1;
headerblock1.pNextBlock = &headerblock2;
/*construct subblock1 of headerblock1*/
subblock1.entry_attribute_ID = LOG_ERROR_DMI_VENDOR_TAG;
subblock1.comparison_operator = LOG_ERROR_EQUAL;
subblock1.comparison_data_ptr = &manufacturer_name;
subblock1.next_subblock = NULL;
/*------------construct headerblock2----------------------*/
headerblock2.pSubblock = &subblock2;
headerblock2.pNextBlock = NULL;
/*construct subblock2 of headerblock2*/
subblock2.entry_attribute_ID = LOG_ERROR_SEVERITY;
subblock2.comparison_operator = LOG_ERROR_LESS_THAN;
subblock2.comparison_data_ptr = severity;
subblock2.comparison_data_length = sizeof(ULONG);
subblock2.next_subblock = &subblock3;
/*construct subblock3 of headerblock2*/
subblock3.entry_attribute_ID = LOG_ERROR_ENTRY_ID;
subblock3.comparison_operator = LOG_ERROR_GREATER_THAN;
subblock3.comparison_data_ptr = entry_id;
subblock3.comparison_data_length = sizeof(ULONG);
subblock3.next_subblock = null;
/* Construct the LogReadEntry parameter packet. */
read_entry_packet.packet_size = sizeof(LREREQUEST);
read_entry_packet.packet_revision_number = LF_UNI_API;
read_entry_packet.log_file_ID = ERROR_LOG_FILE_ID;
read_entry_packet.flags = START_AT_FIRST_ENTRY;
read_entry_packet.pEventKey = &EventKey;
read_entry_packet.pFilter = &filter;
log_entry_buffer_length = sizeof(log_entry_buffer);
read_entry_packet.pLogEntryBufferLength = &log_entry_buffer_length;
read_entry_packet.LogEntryBuffer = &log_entry_buffer;
rc = LogReadEntry(service, /*service*/
&read_entry_packet); /*parameter packet*/
if (rc |= 0)
{
printf("LogReadEntry error: return code = %d",rc);
return;
}