Logging events

Loggers are offered from: Skynet\EventLogger
Skynet has complex logging system. It stores events logs (includes requests, responses and more) in two different places - as text files on server and in database.
By default, both of these options are enabled but you can disable/or enable them into your config file.

Text files logs are stored in specified in config file location (default is: /logs).
In database, you will see all of your stored data by switching your View Mode in Skynet Control Panel to Database View.

Records with logs can be removed by clicking on Delete button or you can erasing all records by one click via Delete all button.

You can easy generate .txt files from specified records by clicking on Generate TXT button on record.

Text file logs can be viewed via Control Panel also by switching view to TXT LOGS mode.

Creating custom logs



You can create custom logs simply in your Event Listeners.
In your listener just use method:

$this->addLog($message);

where:

$message is string value with any text message.
By method above a log will be saved into database and into text file in your logs folder.

Example:

/src/SkynetUser/MyListener.php:
public function onResponse($context)
{
if($context == "afterReceive")
{
$this->addLog('1..2...3...Response received');
}
}

Code above will save log with message "1..2...3...Response received".
You can use $this->addLog() in every place of your Event Listener.

All custom logs created by method above are stores in database table:

skynet_logs_user

and into logs directory with pattern:

{LOGS_DIR}/{TIME}_log_{CLUSTER_ADDRESS}_{NUMBER}.txt

Event Loggers are based on factory design so you can create your own logging system and register it into Skynet.

Loggers factory is placed in class:

/src/Skynet/EventLogger/SkynetEventLoggersFactory.php

You can register custom loggers here:

 /**
* Registers Event Loggers classes in registry
*/
private function registerEventListeners()
{
$this->register('emailer', new SkynetEventListenerEmailer());
$this->register('databaseLogger', new SkynetEventListenerLoggerDatabase());
$this->register('fileLogger', new SkynetEventListenerLoggerFiles());
}

Every custom Event Looger must extends abstract class:

SkynetEventListenerAbstract

and implements interface:

SkynetEventListenerInterface

Loggers are executes at the end of code after the Listeners.

Database logs



Every Skynet cluster uses it own database to store database logs.
At default, Skynet creates tables above to store logs:

- Logs: user logs [skynet_logs_user] - stores user log
- Logs: Responses [skynet_logs_responses] - stores responses
- Logs: Requests [skynet_logs_requests] - stores requests
- Logs: Echo [skynet_logs_echo] - stores echo commands
- Logs: Broadcasts [skynet_logs_broadcast] - stores broadcast commands
- Logs: Errors [skynet_errors] - stores errors
- Logs: Access Errors [skynet_logs_access_errors] - stores security errors (unathorized access to Panel and incorrect KEY ID in connections)
- Logs: Self-updates [skynet_logs_selfupdate] - stores update procedures


Text logs


Text logs are stored in specified in config file directory.
You can set directory for logs by setting option:

$config['logs_dir']

in your config file in /src/SkynetUser/SkynetConfig.php

Every log file is creating by pattern:

{LOGS_DIR}/{TIME}_{EVENTNAME}_{CLUSTER_ADDRESS}_{NUMBER}.txt

Logging specified events can be configured in config file by setting options:

$config['logs_txt_{EVENTNAME}']

to TRUE or FALSE.

NOTE: Remember that every event is logged, so your logs directory may includes lot of files after longer time. You should delete old, unused logs every once in a while.
Full API Documentation is included in Skynet packages available on GitHub.