Creating custom Site Log entries

To insert log messages to the Site log (Admin > Tools > Site log) in your custom PHP scripts you can use Log class.
The first step is to enable API usage as described on PHP and Saurus CMS page.


Example for the simplest message:

new Log(array(
    'component' => 'my_extension',
    'message' => 'Hello World!',
));

The Log::Log() method takes only one argument an array. This example writes into the log 'Hello World!', currently logged users name and user_id, the time, type of message, action taken and component.

The component is a free string up to 256 characters and you should always add it to your message, this makes it easier to distinguish between the CMS's messages and your own.

If no message type is given then it will be marked as 'message'. There are 3 other message types: ERROR, WARNING and NOTICE. Currently the ERROR messages are highlighted with a light red background in the Site log view. WARNING and NOTICE will receive similar color codings. Example:

new Log(array(
    'component' => 'my_extension',
    'type' => 'ERROR',
    'message' => 'All is lost!!',
));


You can also mark what action was taken like so:

new Log(array(
    'component' => 'my_extension',
    'type' => 'ERROR',
    'action' => 'delete',
    'message' => 'All is lost!!',
));

Complete list of actions is:

'none'
'log in'
'log out'
'create'
'delete'
'update'
'import'
'export'
'license download'
'connect'
'sync'
'lock'
'unlock'
'access'
'cancel'
'publish'
'hide'
'replace'
'optimize'
'send'
'start'
'end'
'disable'
'enable'
'check'

with 'none' being default.
They can also be seen from the return of Log::getActionsArray() method.

You can also specify what CMS object was involved, this defaults to 0:

new Log(array(
    'component' => 'my_extension',
    'type' => 'ERROR',
    'action' => 'delete',
    'message' => 'All is lost!!',
    'objekt_id' => 10023,
));

And who is responsible:

new Log(array(
    'component' => 'my_extension',
    'type' => 'ERROR',
    'action' => 'delete',
    'message' => 'All is lost!!',
    'objekt_id' => 10023,
    'user_id' => 45,
));

If the user_id is not specified, currently looged in users ID will be used and if there is no user logged in, the message creator will be marked as "system".