« Back to Product

Documentation

UC_GetLastLogMessages

 array UC_GetLastLogMessages (int $InstanceID, int $Type) 

Parameters

InstanceID

ID for the Util Control

Type

Message type from 0 to 6 (see table in the description)

Returns

An array with one entry per message, starting with the oldest one. Each entry contains the following key => value pairs:

Index Type Description
Message string Text of the message
Sender string Name of the sender, e.g. "Kernel" or the module name. Shorter names are padded with spaces to 20 characters
SenderID integer ID of the sender, e.g. the InstanceID for messages of instances. 0 for messages of the kernel and from IPS_LogMessage
TimeStamp integer Unix timestamp of the message

Description

The function returns the messages of the message type Type that were written to the log most recently. For this purpose, the Util Control keeps a separate buffer in memory for each message type, which contains the last 25 messages. If another message is added, the oldest one is discarded. The number can be changed with the special switch "LogMessageCount"; the value is read when the instance is created, i.e. when IP-Symcon starts. After a restart the buffers are empty, UC_ResetLastLogMessages clears them as well.

Type Constant Name in the log Note
0 KL_MESSAGE MESSAGE
1 KL_SUCCESS SUCCESS
2 KL_NOTIFY NOTIFY
3 KL_WARNING WARNING
4 KL_ERROR ERROR
5 KL_DEBUG DEBUG Always empty, debug messages are not forwarded
6 KL_CUSTOM CUSTOM e.g. messages from IPS_LogMessage
Warning

Type is not the message ID of the constant but its offset to KL_MESSAGE, e.g. KL_ERROR - KL_MESSAGE = 4. Values outside of 0 to 6, e.g. KL_ERROR directly, result in the error "Type must be between 0 and 6".

Only messages that occur while IP-Symcon is ready are recorded (not during startup and shutdown). Debug messages (KL_DEBUG) are not forwarded and are therefore never recorded, neither are messages that are filtered out by the special switch "LogfileFilter". The number of messages per type is returned by UC_GetLogMessageStatistics.

The ID of the Util Control instance can be determined e.g. with IPS_GetInstanceListByModuleID and the module GUID {B69010EA-96D5-46DF-B885-24821B8C8DBD}. If InstanceID does not exist, the function fails with "Instance #... does not exist", if the instance belongs to another module, with "Instance does not implement this function".

Example

// Determine the ID of the Util Control instance
$id = IPS_GetInstanceListByModuleID('{B69010EA-96D5-46DF-B885-24821B8C8DBD}')[0];

// Output all stored error messages
foreach (UC_GetLastLogMessages($id, KL_ERROR - KL_MESSAGE) as $message) {
    echo date('d.m.Y H:i:s', $message['TimeStamp']) . ' | ' . trim($message['Sender']) . ' | ' . $message['Message'] . PHP_EOL;
}

print_r(UC_GetLastLogMessages($id, KL_SUCCESS - KL_MESSAGE));

/* e.g. returns:
Array
(
    [0] => Array
        (
            [Message] => *** IPS READY
            [Sender] => Kernel
            [SenderID] => 0
            [TimeStamp] => 1700000000
        )

)
*/
Any questions?