Logging guide
If there’s a problem with your plugin, it’s useful to have some indicators in place that help you locate the cause of the problem. You can achieve this by implementing logs. You can also use logs to provide the user with other useful information.
Logs are written to the Data log. For further information on configuration and search options, refer to the
Data log page of the plentymarkets manual.
In the case of a plugin, the Integration is the namespace of the plugin. The Identifier is the function that implements the logging.
Logging
Logs are registered in a ServiceProvider
. Once registered, they can be called on in a Controller
.
The ServiceProvider
has to import and use the Plenty\Log\Services\ReferenceContainer
service. You should also
import and use Plenty\Log\Exceptions\ReferenceTypeException
to catch exceptions on registration.
<?php
namespace PluginNameSpace\Providers;
use Plenty\Plugin\ServiceProvider;
use Plenty\Log\Services\ReferenceContainer;
use Plenty\Log\Exceptions\ReferenceTypeException;
class MyServiceProvider extends ServiceProvider
{
public function register()
{
}
public function boot(ReferenceContainer $referenceContainer)
{
// Register reference types for logs.
try
{
$referenceContainer->add([ 'myLogReference' => 'myLogReference' ]); // reference is optional
}
catch(ReferenceTypeException $ex)
{
}
}
}
After registering the reference, you can call on it in a Controller
.
The Controller
has to import and use Plenty\Plugin\Log\Loggable
.
<?php
namespace PluginNameSpace\Providers;
use Plenty\Plugin\Controller;
use Plenty\Plugin\Log\Loggable;
class MyController extends Controller
{
use Loggable;
public function doSomething ()
{
$myBusinessAction->doSomething();
$this
->getLogger('MyController_doSomething')
->logLevel('PluginNameSpace::message', [additionalInformation]); // additional information is optional
->setReferenceType('myLogReference') // optional
->setReferenceValue($myBusinessAction->getActionId()) // optional
}
}
Each log has the following properties:
Property | Description |
---|---|
Log level |
The level associated with the log. The following levels are available, in order of severity from highest to lowest:
Report information, as well as the log levels |
Message |
Detailed information on the logged event. For the log levels |
|
Provides a filter option for log entries. Has to be unique. |
|
Provides a second level filter option for a reference type, for example a specific ID. == Reporting Reporting is a special form of logging used for providing information about expected events. For example, you can inform the user every time at the end of every order import process how many new orders were imported or skipped. Reporting is implemented similarly to logging. The only difference is that the
|